@@ -327,13 +327,13 @@ public function testDoesNotAllowCRLFInjectionWhenCallingWithAddedHeader($name, $
327327 public function testWithHeaderAllowsHeaderContinuations (): void
328328 {
329329 $ message = $ this ->message ->withHeader ('X-Foo-Bar ' , "value, \r\n second value " );
330- $ this ->assertSame ("value, \r\n second value " , $ message ->getHeaderLine ('X-Foo-Bar ' ));
330+ $ this ->assertSame ("value, second value " , $ message ->getHeaderLine ('X-Foo-Bar ' ));
331331 }
332332
333333 public function testWithAddedHeaderAllowsHeaderContinuations (): void
334334 {
335335 $ message = $ this ->message ->withAddedHeader ('X-Foo-Bar ' , "value, \r\n second value " );
336- $ this ->assertSame ("value, \r\n second value " , $ message ->getHeaderLine ('X-Foo-Bar ' ));
336+ $ this ->assertSame ("value, second value " , $ message ->getHeaderLine ('X-Foo-Bar ' ));
337337 }
338338
339339 /** @return non-empty-array<non-empty-string, array{non-empty-string}> */
@@ -357,6 +357,28 @@ public function testWithHeaderTrimsWhitespace(string $value): void
357357 $ this ->assertSame (trim ($ value , "\t " ), $ message ->getHeaderLine ('X-Foo-Bar ' ));
358358 }
359359
360+ /** @return non-empty-array<non-empty-string, array{non-empty-string}> */
361+ public function headersWithContinuation (): array
362+ {
363+ return [
364+ 'space ' => ["foo \r\n bar " ],
365+ 'tab ' => ["foo \r\n\tbar " ],
366+ ];
367+ }
368+
369+ /**
370+ * @dataProvider headersWithContinuation
371+ */
372+ public function testWithHeaderNormalizesContinuationToNotContainNewlines (string $ value ): void
373+ {
374+ $ message = $ this ->message ->withHeader ('X-Foo-Bar ' , $ value );
375+ // Newlines must no longer appear.
376+ $ this ->assertStringNotContainsString ("\r" , $ message ->getHeaderLine ('X-Foo-Bar ' ));
377+ $ this ->assertStringNotContainsString ("\n" , $ message ->getHeaderLine ('X-Foo-Bar ' ));
378+ // But there must be at least one space.
379+ $ this ->assertStringContainsString (' ' , $ message ->getHeaderLine ('X-Foo-Bar ' ));
380+ }
381+
360382 /** @return non-empty-array<non-empty-string, array{int|float}> */
361383 public function numericHeaderValuesProvider (): array
362384 {
0 commit comments