-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Allow query params to be formated with a preservered order #26202
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
[HttpFoundation] Allow query params to be formated with a preservered order #26202
Conversation
ecdd581
to
42abf6b
Compare
* | ||
* @return string A normalized query string for the Request | ||
*/ | ||
public static function normalizeQueryString($qs) | ||
public static function normalizeQueryString($qs, $preserveOrder = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be bool $preserveOrder = false
For the rationale behind this PR, see api-platform/core#1710. |
42abf6b
to
56d9613
Compare
* | ||
* @return string A normalized query string for the Request | ||
*/ | ||
public static function normalizeQueryString($qs) | ||
public static function normalizeQueryString($qs, bool $preserveOrder = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a new argument is a BC break, isn't it?
This needs a BC layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally right, I'll work on this sorry.
Actually, shouldn't this be the default? it looks like a bug to me, the order matters for keyed arrays |
@nicolas-grekas Well let me know, it also feels buggy to me but it actually exactly do what it says in the description (order alphabetically). I can update the PR and even target a lower branch if it is considered as a bug fix. If not, what would be the best way of adding a BC layer:
|
See #26214 for my proposal on 2.7 :) |
Ok then |
…malization (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
This PR aimed to allow using the queryString normalization without reordering the parameters name.
It can be specifically usefull in the context of building API and parsing urls like
/foo?order[baz]=asc&order[bar]=asc
. In this case, in order to apply an order condition on a query where preserving the order of the parameter matters likeORDER BY baz ASC, bar ASC
for example , it would be nice to have this possibility.