Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.

convert pluses to spaces when decoding cookies#62

Closed
hx wants to merge 1 commit intocarhartl:masterfrom
hx:master
Closed

convert pluses to spaces when decoding cookies#62
hx wants to merge 1 commit intocarhartl:masterfrom
hx:master

Conversation

@hx
Copy link

@hx hx commented Apr 25, 2012

This fix will let you set cookies with PHP's setcookie() method (and probably other languages too), and see spaces as spaces (previously they were plus signs).

@carhartl
Copy link
Owner

carhartl commented Jul 8, 2012

As I had stated somewhere else before, what if someone specifically wants to put a "+" into the cookie value? With this pull request this would be changed to " " upon reading (unless using raw), which is not desired obviously in such a case. That said, we cannot simply assume all pluses were having to change to " ".

My take on this is - now that we have default options, this is much easier - providing a decode option for this, so that the developer can hook whatever decoding method required into it:

$.cookie.defaults.decode = function(s) { return s.replace(/\+/g, ' '); };

This were all a developer needed to do.

@carhartl carhartl closed this Jul 8, 2012
@carhartl
Copy link
Owner

carhartl commented Jul 8, 2012

Alternatively we'd need to convert pluses first, before doing decodeURIComponent, as mentioned here: #13 (comment)

Would you like to adapt the pull request?

@carhartl
Copy link
Owner

carhartl commented Jul 9, 2012

My bad, I overlooked that you were already replacing before decoding... sorry.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants