Skip to content

Commit 02b965b

Browse files
Merge branch '2.4' into 2.5
2 parents 41c92ec + 0454e12 commit 02b965b

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## 2.4.5 - 2023-04-17
11+
12+
### Fixed
13+
14+
- Prevent possible warnings on unset variables in `ServerRequest::normalizeNestedFileSpec`
15+
- Fixed `Message::bodySummary` when `preg_match` fails
16+
- Fixed header validation issue
17+
1018
## 2.4.4 - 2023-03-09
1119

1220
### Changed

src/Message.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function bodySummary(MessageInterface $message, int $truncateAt =
7777

7878
// Matches any printable character, including unicode characters:
7979
// letters, marks, numbers, punctuation, spacing, and separators.
80-
if (preg_match('/[^\pL\pM\pN\pP\pS\pZ\n\r\t]/u', $summary)) {
80+
if (preg_match('/[^\pL\pM\pN\pP\pS\pZ\n\r\t]/u', $summary) !== 0) {
8181
return null;
8282
}
8383

src/MessageTrait.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,9 @@ private function assertHeader($header): void
224224
));
225225
}
226226

227-
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/', $header)) {
227+
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/D', $header)) {
228228
throw new \InvalidArgumentException(
229-
sprintf(
230-
'"%s" is not valid header name',
231-
$header
232-
)
229+
sprintf('"%s" is not valid header name.', $header)
233230
);
234231
}
235232
}
@@ -257,8 +254,10 @@ private function assertValue(string $value): void
257254
// Clients must not send a request with line folding and a server sending folded headers is
258255
// likely very rare. Line folding is a fairly obscure feature of HTTP/1.1 and thus not accepting
259256
// folding is not likely to break any legitimate use case.
260-
if (! preg_match('/^[\x20\x09\x21-\x7E\x80-\xFF]*$/', $value)) {
261-
throw new \InvalidArgumentException(sprintf('"%s" is not valid header value', $value));
257+
if (! preg_match('/^[\x20\x09\x21-\x7E\x80-\xFF]*$/D', $value)) {
258+
throw new \InvalidArgumentException(
259+
sprintf('"%s" is not valid header value.', $value)
260+
);
262261
}
263262
}
264263
}

tests/RequestTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ public function provideHeaderValuesContainingNotAllowedChars(): iterable
332332
// Line folding is technically allowed, but deprecated.
333333
// We don't support it.
334334
["new\r\n line"],
335+
["newline\n"],
336+
["\nnewline"],
337+
["newline\r\n"],
338+
["\r\nnewline"],
335339
];
336340

337341
for ($i = 0; $i <= 0xff; $i++) {
@@ -349,6 +353,7 @@ public function provideHeaderValuesContainingNotAllowedChars(): iterable
349353
}
350354

351355
$tests[] = ["foo" . \chr($i) . "bar"];
356+
$tests[] = ["foo" . \chr($i)];
352357
}
353358

354359
return $tests;

tests/ResponseTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ public function invalidWithHeaderProvider(): iterable
288288
yield [[], 'foo', 'Header name must be a string but array provided.'];
289289
yield [false, 'foo', 'Header name must be a string but boolean provided.'];
290290
yield [new \stdClass(), 'foo', 'Header name must be a string but stdClass provided.'];
291+
yield ['', 'foo', "\"\" is not valid header name."];
292+
yield ["Content-Type\r\n\r\n", 'foo', "\"Content-Type\r\n\r\n\" is not valid header name."];
293+
yield ["Content-Type\r\n", 'foo', "\"Content-Type\r\n\" is not valid header name."];
294+
yield ["Content-Type\n", 'foo', "\"Content-Type\n\" is not valid header name."];
295+
yield ["\r\nContent-Type", 'foo', "\"\r\nContent-Type\" is not valid header name."];
296+
yield ["\nContent-Type", 'foo', "\"\nContent-Type\" is not valid header name."];
297+
yield ["\n", 'foo', "\"\n\" is not valid header name."];
298+
yield ["\r\n", 'foo', "\"\r\n\" is not valid header name."];
299+
yield ["\t", 'foo', "\"\t\" is not valid header name."];
291300
}
292301

293302
public function testHeaderValuesAreTrimmed(): void

0 commit comments

Comments
 (0)