Skip to content

decodes some special chars in a URL query #12223

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

Merged
merged 1 commit into from
Oct 27, 2014

Conversation

dawehner
Copy link
Contributor

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

@@ -331,7 +331,7 @@ public function testUrlEncoding()
$routes = $this->getRoutes('test', new Route("/$chars/{varpath}", array(), array('varpath' => '.+')));
$this->assertSame('/app.php/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'
.'/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'
.'?query=%40%3A%5B%5D%2F%28%29%2A%27%22+%2B%2C%3B-._%7E%26%24%3C%3E%7C%7B%7D%25%5C%5E%60%21%3Ffoo%3Dbar%23id',
.'?query=@:%5B%5D/%28%29*%27%22++,;-._%7E%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unencoding the = is not safe. There is a difference between ?foo%3Dbar=baz and ?foo=bar=baz!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One means array('foo=bar' => 'baz') and the other array('foo' => 'bar=baz')

@dawehner
Copy link
Contributor Author

You are absolute right, let's imit it to the two special cases described in the RFC

@fabpot
Copy link
Member

fabpot commented Oct 14, 2014

@Tobion Is it good now?

$url .= '?'.$query;
// "/" and "?" can be left decoded for better user experience, see
// http://tools.ietf.org/html/rfc3986#section-3.4
$url .= '?'.strtr($query, array('%2F' => '/', '%3F' => '?'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree that decoding ? makes things better. For example: /path/sub?foo?bar it gets very hard to see where the query part starts. I think other chars are more worth to keep decoded like @, e.g. when you pass an email like ?to=me@example.org. So I think its ok to use $this->decodedChars BUT without = and & (in case somebody added it in a subclass). Just unset them in a local variable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the documentation of $this->decodedChars should be updated then to mention its also used for query decoding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn + is probably risky as well. Since it is the encoded form of space when using forms.
So ?foo=bar+baz will result in _GET["foo"] = 'bar baz' which is bad.

So I guess we should just decode the / for now.

@dawehner
Copy link
Contributor Author

Okay, let's just do the "/" for now.

@fabpot
Copy link
Member

fabpot commented Oct 27, 2014

Thank you @dawehner.

@fabpot fabpot merged commit cd2c2e3 into symfony:master Oct 27, 2014
fabpot added a commit that referenced this pull request Oct 27, 2014
This PR was merged into the 2.6-dev branch.

Discussion
----------

decodes some special chars in a URL query

| Q             | A
| ------------- | ---
| Bug fix?      | yes|no (not sure :) )
| New feature?  | no
| BC breaks?    | yes|no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12200
| License       | MIT
| Doc PR        |

Commits
-------

cd2c2e3 decodes some special chars in a URL query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants