From 5fa549e42a8aa387fbcde6f9a272b245ef953448 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 20 Mar 2022 21:16:08 +0000 Subject: [PATCH] Release 2.1.2 --- 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 bfbd1938..91704421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## 2.1.2 - 2022-03-20 + +### Fixed + +- Correct header value validation + ## 2.1.1 - 2022-03-20 ### Fixed diff --git a/src/MessageTrait.php b/src/MessageTrait.php index 809502c1..a8696b98 100644 --- a/src/MessageTrait.php +++ b/src/MessageTrait.php @@ -259,7 +259,7 @@ private function assertValue(string $value): void // 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 f8c04bf4..71d90b21 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -176,6 +176,17 @@ public function testHostIsAddedFirst(): void ], $r->getHeaders()); } + public function testHeaderValueWithWhitespace(): void + { + $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(): void { $r = new Request('GET', 'http://foo.com/baz?bar=bam', [