You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
…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
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'sdecodeURIComponent
When the
Cookie
is stringified and attached as a header on the response, it is encoding the cookie value usingurlencode()
, which doesn't follow RFC 3986, instead of usingrawurlencode()
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 ofrawurlencode
? 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.The text was updated successfully, but these errors were encountered: