Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] Don't reorder nested query string keys #26214

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
wants to merge 1 commit into from

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets api-platform/core#1710
License MIT
Doc PR -

Normalization shouldn't apply to recursive structures.
Replaces #26202

@fabpot
Copy link
Member

fabpot commented Feb 19, 2018

I don't understand why some keys should be ordered while others should not. I understand it for the specific use case described, but I fail to see why this should a good thing in general. The goal of this method is to ensure that 2 URLs stay equivalent even if query parameters are reordered or encoding is different.

In any case, it looks like a BC break to me.

@nicolas-grekas
Copy link
Member Author

A basic requirement of any normalization process is to not remove any useful information from the original data.
Right now, foo[]=Z&foo[]=A is transformed foo[]=A&foo[]=Z. This doesn't mean the same.
This looks like a hard break of this requirement to me, thus a bug.
With this PR, the root keys are reordered, but not the nested ones:
foo[]=Z&bar=123&foo[]=A becomes bar=123&&foo[]=Z&foo[]=A

@fabpot
Copy link
Member

fabpot commented Feb 19, 2018

I do understand the changes made here. But this IS a BC break. So, no way we merge this into 2.7.

@nicolas-grekas
Copy link
Member Author

OK, let's fix this on master

@nicolas-grekas nicolas-grekas deleted the request-qs-norm branch February 19, 2018 09:01
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.

5 participants