From 337e3ad8e5716c15f9657bd214d16cc5e69df268 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 20 Mar 2022 21:51:18 +0000 Subject: [PATCH] Release 1.8.5 (#491) --- CHANGELOG.md | 6 ++++++ src/MessageTrait.php | 2 +- tests/RequestTest.php | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5f80274..f177f583 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +## 1.8.5 - 2022-03-20 + +### Fixed + +- Correct header value validation + ## 1.8.4 - 2022-03-20 ### Fixed diff --git a/src/MessageTrait.php b/src/MessageTrait.php index 459b104d..0ac8663d 100644 --- a/src/MessageTrait.php +++ b/src/MessageTrait.php @@ -263,7 +263,7 @@ private function assertValue($value) // Clients must not send a request with line folding and a server sending folded headers is // likely very rare. Line folding is a fairly obscure feature of HTTP/1.1 and thus not accepting // folding is not likely to break any legitimate use case. - if (! preg_match('/^(?:[\x21-\x7E\x80-\xFF](?:[\x20\x09]+[\x21-\x7E\x80-\xFF])?)*$/', $value)) { + if (! preg_match('/^[\x20\x09\x21-\x7E\x80-\xFF]*$/', $value)) { throw new \InvalidArgumentException(sprintf('"%s" is not valid header value', $value)); } } diff --git a/tests/RequestTest.php b/tests/RequestTest.php index d943dc50..3e0ebce9 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -174,6 +174,17 @@ public function testHostIsAddedFirst() ], $r->getHeaders()); } + public function testHeaderValueWithWhitespace() + { + $r = new Request('GET', 'https://example.com/', [ + 'User-Agent' => 'Linux f0f489981e90 5.10.104-linuxkit 1 SMP Wed Mar 9 19:05:23 UTC 2022 x86_64' + ]); + self::assertSame([ + 'Host' => ['example.com'], + 'User-Agent' => ['Linux f0f489981e90 5.10.104-linuxkit 1 SMP Wed Mar 9 19:05:23 UTC 2022 x86_64'] + ], $r->getHeaders()); + } + public function testCanGetHeaderAsCsv() { $r = new Request('GET', 'http://foo.com/baz?bar=bam', [