8000 [HttpFoundation] Recursively order query string keys in `Request::normalizeQueryString()` by bradjones1 · Pull Request #57190 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Recursively order query string keys in Request::normalizeQueryString() #57190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Recursively order query strings
  • Loading branch information
bradjones1 committed May 27, 2024
commit 99a25d37a467b07e3996bd1cbba6bd51dfd97211
10 changes: 9 additions & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,15 @@ public static function normalizeQueryString(?string $qs): string
}

$qs = HeaderUtils::parseQuery($qs);
ksort($qs);
$recursive_sort = function (&$array) use (&$recursive_sort) {
foreach ($array as &$v) {
if (is_array($v)) {
$recursive_sort($v);
}
}
ksort($array);
};
$recursive_sort($qs);

return http_build_query($qs, '', '&', \PHP_QUERY_RFC3986);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,9 @@ public static function getQueryStringNormalizationData()
// PHP also does not include them when building _GET.
['foo=bar&=a=b&=x=y', 'foo=bar', 'removes params with empty key'],

// Don't reorder nested query string keys
// Provide predictable ordering of nested query string keys.
['foo[]=Z&foo[]=A', 'foo%5B0%5D=Z&foo%5B1%5D=A', 'keeps order of values'],
['foo[Z]=B&foo[A]=B', 'foo%5BZ%5D=B&foo%5BA%5D=B', 'keeps order of keys'],
['foo[Z]=A&foo[A]=B', 'foo%5BA%5D=B&foo%5BZ%5D=A', 'nested keys are reordered but values are maintained'],

['utf8=✓', 'utf8=%E2%9C%93', 'encodes UTF-8'],
];
Expand Down
0