Skip to content

Commit

Permalink
Correctly suppress empty list items in Header::normalize()
Browse files Browse the repository at this point in the history
RFC 7230#7:

> For compatibility with legacy list rules, a recipient MUST parse and ignore a
> reasonable number of empty list elements:

and

> Empty elements do not contribute to the count of elements present.
  • Loading branch information
TimWolla committed Oct 5, 2021
1 parent c668720 commit f7d9989
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ public static function normalize($header): array
foreach ((array) $header as $value) {
foreach ((array) $value as $v) {
if (strpos($v, ',') === false) {
$result[] = $v;
$trimmed = trim($v);
if ($trimmed !== '') {
$result[] = $trimmed;
}
continue;
}
foreach (preg_split('/,(?=([^"]*"([^"]|\\\\.)*")*[^"]*$)/', $v) as $vv) {
$result[] = trim($vv);
$trimmed = trim($vv);
if ($trimmed !== '') {
$result[] = $trimmed;
}
}
}
}
Expand Down

0 comments on commit f7d9989

Please sign in to comment.