Skip to content

Commit

Permalink
bug #54910 [HttpFoundation]  filter out empty HTTP header parts (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 5.4 branch.

Discussion
----------

[HttpFoundation]  filter out empty HTTP header parts

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54868
| License       | MIT

Commits
-------

7d6d8cd97f filter out empty HTTP header parts
  • Loading branch information
nicolas-grekas committed May 15, 2024
2 parents e13c456 + fdd485e commit 53be869
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 53be869

Please sign in to comment.