Skip to content

Commit

Permalink
filter out empty HTTP header parts
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh authored and nicolas-grekas committed May 15, 2024
1 parent fd44aca commit fdd485e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion HeaderUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ private static function groupParts(array $matches, string $separators, bool $fir
}

foreach ($partMatches as $matches) {
$parts[] = '' === $separators ? self::unquote($matches[0][0]) : self::groupParts($matches, $separators, false);
if ('' === $separators && '' !== $unquoted = self::unquote($matches[0][0])) {
$parts[] = $unquoted;
} elseif ($groupedParts = self::groupParts($matches, $separators, false)) {
$parts[] = $groupedParts;
}
}

return $parts;
Expand Down
2 changes: 2 additions & 0 deletions Tests/AcceptHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static function provideFromStringData()
{
return [
['', []],
[';;;', []],
['0', [new AcceptHeaderItem('0')]],
['gzip', [new AcceptHeaderItem('gzip')]],
['gzip,deflate,sdch', [new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')]],
["gzip, deflate\t,sdch", [new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')]],
Expand Down

0 comments on commit fdd485e

Please sign in to comment.