Skip to content

Commit e4490ca

Browse files
Release 1.9.1
2 parents 0e75375 + c8b21de commit e4490ca

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

CHANGELOG.md

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

1010
## Unreleased
1111

12+
## 1.9.1 - 2023-04-17
13+
14+
### Fixed
15+
16+
- Fixed header validation issue
17+
1218
## 1.9.0 - 2022-06-20
1319

1420
### Added

src/MessageTrait.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,9 @@ private function assertHeader($header)
226226
throw new \InvalidArgumentException('Header name can not be empty.');
227227
}
228228

229-
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/', $header)) {
229+
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/D', $header)) {
230230
throw new \InvalidArgumentException(
231-
sprintf(
232-
'"%s" is not valid header name',
233-
$header
234-
)
231+
sprintf('"%s" is not valid header name.', $header)
235232
);
236233
}
237234
}
@@ -263,8 +260,10 @@ private function assertValue($value)
263260
// Clients must not send a request with line folding and a server sending folded headers is
264261
// likely very rare. Line folding is a fairly obscure feature of HTTP/1.1 and thus not accepting
265262
// folding is not likely to break any legitimate use case.
266-
if (! preg_match('/^[\x20\x09\x21-\x7E\x80-\xFF]*$/', $value)) {
267-
throw new \InvalidArgumentException(sprintf('"%s" is not valid header value', $value));
263+
if (! preg_match('/^[\x20\x09\x21-\x7E\x80-\xFF]*$/D', $value)) {
264+
throw new \InvalidArgumentException(
265+
sprintf('"%s" is not valid header value.', $value)
266+
);
268267
}
269268
}
270269
}

tests/RequestTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ public function provideHeaderValuesContainingNotAllowedChars()
269269
// Line folding is technically allowed, but deprecated.
270270
// We don't support it.
271271
["new\r\n line"],
272+
["newline\n"],
273+
["\nnewline"],
274+
["newline\r\n"],
275+
["\r\nnewline"],
272276
];
273277

274278
for ($i = 0; $i <= 0xff; $i++) {
@@ -286,6 +290,7 @@ public function provideHeaderValuesContainingNotAllowedChars()
286290
}
287291

288292
$tests[] = ["foo" . \chr($i) . "bar"];
293+
$tests[] = ["foo" . \chr($i)];
289294
}
290295

291296
return $tests;

tests/ResponseTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ public function invalidWithHeaderProvider()
284284
[[], 'foo', 'Header name must be a string but array provided.'],
285285
[false, 'foo', 'Header name must be a string but boolean provided.'],
286286
[new \stdClass(), 'foo', 'Header name must be a string but stdClass provided.'],
287+
["", 'foo', "Header name can not be empty."],
288+
["Content-Type\r\n\r\n", 'foo', "\"Content-Type\r\n\r\n\" is not valid header name."],
289+
["Content-Type\r\n", 'foo', "\"Content-Type\r\n\" is not valid header name."],
290+
["Content-Type\n", 'foo', "\"Content-Type\n\" is not valid header name."],
291+
["\r\nContent-Type", 'foo', "\"\r\nContent-Type\" is not valid header name."],
292+
["\nContent-Type", 'foo', "\"\nContent-Type\" is not valid header name."],
293+
["\n", 'foo', "\"\n\" is not valid header name."],
294+
["\r\n", 'foo', "\"\r\n\" is not valid header name."],
295+
["\t", 'foo', "\"\t\" is not valid header name."],
287296
]);
288297
}
289298

0 commit comments

Comments
 (0)