Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8e64fe7

Browse filesBrowse files
[HttpFoundation] Don't reorder nested query string keys
1 parent 233774c commit 8e64fe7
Copy full SHA for 8e64fe7

File tree

2 files changed

+9
-5
lines changed
Filter options

2 files changed

+9
-5
lines changed

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ public static function normalizeQueryString($qs)
660660

661661
$parts = array();
662662
$order = array();
663+
$index = 0;
663664

664665
foreach (explode('&', $qs) as $param) {
665666
if ('' === $param || '=' === $param[0]) {
@@ -670,17 +671,16 @@ public static function normalizeQueryString($qs)
670671
}
671672

672673
$keyValuePair = explode('=', $param, 2);
674+
$key = urldecode($keyValuePair[0]);
673675

674676
// GET parameters, that are submitted from a HTML form, encode spaces as "+" by default (as defined in enctype application/x-www-form-urlencoded).
675677
// PHP also converts "+" to spaces when filling the global _GET or when using the function parse_str. This is why we use urldecode and then normalize to
676678
// RFC 3986 with rawurlencode.
677-
$parts[] = isset($keyValuePair[1]) ?
678-
rawurlencode(urldecode($keyValuePair[0])).'='.rawurlencode(urldecode($keyValuePair[1])) :
679-
rawurlencode(urldecode($keyValuePair[0]));
680-
$order[] = urldecode($keyValuePair[0]);
679+
$parts[] = rawurlencode($key).(isset($keyValuePair[1]) ? '='.rawurlencode(urldecode($keyValuePair[1])) : '');
680+
$order[] = false !== ($i = strpos($key, '[')) ? substr_replace($key, ++$index, 1 + $i) : $key;
681681
}
682682

683-
array_multisort($order, SORT_ASC, $parts);
683+
array_multisort($order, SORT_NATURAL, $parts);
684684

685685
return implode('&', $parts);
686686
}

‎src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,10 @@ public function getQueryStringNormalizationData()
658658
// Ignore pairs with empty key, even if there was a value, e.g. "=value", as such nameless values cannot be retrieved anyway.
659659
// PHP also does not include them when building _GET.
660660
array('foo=bar&=a=b&=x=y', 'foo=bar', 'removes params with empty key'),
661+
662+
// Don't reorder nested query string keys
663+
array('foo[]=Z&foo[]=A', 'foo%5B%5D=Z&foo%5B%5D=A', 'keeps values order'),
664+
array('foo[Z]=B&foo[A]=B', 'foo%5BZ%5D=B&foo%5BA%5D=B', 'keeps keys order'),
661665
);
662666
}
663667

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.