Skip to content

Commit

Permalink
Extend check to discard empty request cookies (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Oct 16, 2022
1 parent 2437d31 commit b654546
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Cookie/RequestCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function fromHeader(string $string): array
try {
foreach ($cookies as $cookie) {
// Ignore zero-length cookie.
if ($cookie === '') {
if (\trim($cookie) === '') {
continue;
}

Expand Down
11 changes: 10 additions & 1 deletion test/Cookie/RequestCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testParsing()
}

/**
* Tests that when a zero-length phantom cookie is trailing due to the terminating semi-colon, it is simply
* Tests that when a zero-length phantom cookie is trailing due to the terminating semicolon, it is simply
* discarded without impacting any other cookies present.
*/
public function testZeroLengthTrailingCookie(): void
Expand All @@ -30,6 +30,15 @@ public function testZeroLengthTrailingCookie(): void
self::assertEquals([new RequestCookie('a', '1')], $cookies);
}

/**
* Tests that trailing whitespace is ignored.
*/
public function testWhitespaceTrailingCookie(): void
{
self::assertCount(1, $cookies = RequestCookie::fromHeader('a=1; '));
self::assertEquals([new RequestCookie('a', '1')], $cookies);
}

public function testInvalidCookieName()
{
$this->expectException(InvalidCookieException::class);
Expand Down

0 comments on commit b654546

Please sign in to comment.