Skip to content

Commit

Permalink
[HttpFoundation] Fixed #5611 - Request::splitHttpAcceptHeader incorre…
Browse files Browse the repository at this point in the history
…ct result order.

* Makes items with equal q-values return in the original provided order.
* Fixes tests to reflect this behavior
  • Loading branch information
kerihenare committed Oct 2, 2012
1 parent 7ebc385 commit 018fcbb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,23 +1051,31 @@ public function splitHttpAcceptHeader($header)
}

$values = array();
$groups = array();
foreach (array_filter(explode(',', $header)) as $value) {
// Cut off any q-value that might come after a semi-colon
if (preg_match('/;\s*(q=.*$)/', $value, $match)) {
$q = (float) substr(trim($match[1]), 2);
$q = substr(trim($match[1]), 2);
$value = trim(substr($value, 0, -strlen($match[0])));
} else {
$q = 1;
}

$groups[$q][] = $value;
}

krsort($groups);

foreach ($groups as $q => $items) {
$q = (float) $q;

if (0 < $q) {
$values[trim($value)] = $q;
foreach ($items as $value) {
$values[trim($value)] = $q;
}
}
}

arsort($values);
reset($values);

return $values;
}

Expand Down

0 comments on commit 018fcbb

Please sign in to comment.