8000 Cookie::__toString() is using urlencode instead of rawurlencode · Issue #23255 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Cookie::__toString() is using urlencode instead of rawurlencode #23255

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
dbhynds opened this issue Jun 21, 2017 · 0 comments
Closed

Cookie::__toString() is using urlencode instead of rawurlencode #23255

dbhynds opened this issue Jun 21, 2017 · 0 comments

Comments

@dbhynds
Copy link
dbhynds commented Jun 21, 2017
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.2

I'm trying to pass an array from my backend to the frontend on a cookie. To do this, I'm converting the array to a stringified json object, and passing that as the value on a Symfony\Component\HttpFoundation\Cookie. The frontend is then converting the string back to a json object using javascript's decodeURIComponent

When the Cookie is stringified and attached as a header on the response, it is encoding the cookie value using urlencode(), which doesn't follow RFC 3986, instead of using rawurlencode() which does follow RFC 3986. The difference is that spaces are encoded as + instead of %20.

The decodeURIComponent adheres to RFC 3986, meaning that when I decode the cookie, I then have to parse the values to replace +s with spaces, which obviously isn't ideal.

Is there a reason that it's using urlencode instead of rawurlencode? Off the top of my head, I can't think of why it would be necessary, but it's possible I'm missing something. I'd be happy to change it and submit a PR, but I wanted to get others' thoughts and input.

nicolas-grekas added a commit that referenced this issue Jul 11, 2017
…javiereguiluz)

This PR was squashed before being merged into the 2.7 branch (closes #23461).

Discussion
----------

Use rawurlencode() to transform the Cookie into a string

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23255
| License       | MIT
| Doc PR        | -

Commits
-------

025dfff Use rawurlencode() to transform the Cookie into a string
twinh added a commit to twinh/wei that referenced this issue Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0