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

[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

Conversation

antograssiot
Copy link
Contributor

@antograssiot antograssiot commented Feb 17, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

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 like ORDER BY baz ASC, bar ASC for example , it would be nice to have this possibility.

*
* @return string A normalized query string for the Request
*/
public static function normalizeQueryString($qs)
public static function normalizeQueryString($qs, $preserveOrder = false)
Copy link
Member

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

@dunglas
Copy link
Member

dunglas commented Feb 17, 2018

For the rationale behind this PR, see api-platform/core#1710.
Reorder causes issues when the order specified by the user matters (for instance the order filter in an API).

@antograssiot antograssiot force-pushed the httpfoundation-queryparam-ordering branch from 42abf6b to 56d9613 Compare February 17, 2018 10:01
@nicolas-grekas nicolas-grekas changed the title [HttpFoundation] Allow query params to be formated with a preservered… [HttpFoundation] Allow query params to be formated with a preservered order Feb 17, 2018
*
* @return string A normalized query string for the Request
*/
public static function normalizeQueryString($qs)
public static function normalizeQueryString($qs, bool $preserveOrder = false)
Copy link
Member

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.

Copy link
Contributor Author

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.

@nicolas-grekas
Copy link
Member

Actually, shouldn't this be the default? it looks like a bug to me, the order matters for keyed arrays

@antograssiot
Copy link
Contributor Author

@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:

  1. adding new method
  2. not declaring the new arg in the function signature and relying on a count on func_get_args
  3. any better idea :)

@nicolas-grekas
Copy link
Member

See #26214 for my proposal on 2.7 :)

@antograssiot
Copy link
Contributor Author

Ok then

@antograssiot antograssiot deleted the httpfoundation-queryparam-ordering branch February 18, 2018 19:03
fabpot added a commit that referenced this pull request Mar 23, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.