You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #26220 [HttpFoundation] Use parse_str() for query strings normalization (nicolas-grekas)
This PR was merged into the 4.1-dev branch.
Discussion
----------
[HttpFoundation] Use parse_str() for query strings normalization
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Follow up of #26214 and #26202
The current normalization logic is both too loose and too broad: it changes the order of recursive data structures, while not normalizing keys.
Since the normalization logic varies by query string parser, I'd like to propose a logic that exactly matches the native PHP one, which is exposed to userland via `parse_str()`. Using this, we accurately remove all useless information, while preserving all the meaningful one.
(The change in `overrideGlobals()` is a bug fix to me btw, the current logic breaks the interpretation of legitimate query strings.)
Commits
-------
5133536 [HttpFoundation] Use parse_str() for query strings normalization
Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+3-24Lines changed: 3 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -629,31 +629,10 @@ public static function normalizeQueryString($qs)
629
629
return'';
630
630
}
631
631
632
-
$parts = array();
633
-
$order = array();
634
-
635
-
foreach (explode('&', $qs) as$param) {
636
-
if ('' === $param || '=' === $param[0]) {
637
-
// Ignore useless delimiters, e.g. "x=y&".
638
-
// Also ignore pairs with empty key, even if there was a value, e.g. "=value", as such nameless values cannot be retrieved anyway.
639
-
// PHP also does not include them when building _GET.
640
-
continue;
641
-
}
642
-
643
-
$keyValuePair = explode('=', $param, 2);
644
-
645
-
// GET parameters, that are submitted from a HTML form, encode spaces as "+" by default (as defined in enctype application/x-www-form-urlencoded).
646
-
// 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
0 commit comments