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

json option prevents parsing regular cookies #358

Closed
d07RiV opened this issue Mar 27, 2015 · 4 comments
Closed

json option prevents parsing regular cookies #358

d07RiV opened this issue Mar 27, 2015 · 4 comments

Comments

@d07RiV
Copy link

d07RiV commented Mar 27, 2015

If I use the json option, the plugin fails to parse regular string cookies set from HTTP headers.

@FagnerMartinsBrack
Copy link
Collaborator

@d07RiV Do you have an example?

@d07RiV
Copy link
Author

d07RiV commented Apr 9, 2015

Just set $.cookie.json to true and it won't be able to parse regular strings if they aren't quoted.

E.g.
PHP:

setcookie("test", "value");

JS:

$.cookie.json = true;
$.cookie("test") // returns undefined

The source reads:

    try {
        // Replace server-side written pluses with spaces.
        // If we can't decode the cookie, ignore it, it's unusable.
        // If we can't parse the cookie, ignore it, it's unusable.
        s = decodeURIComponent(s.replace(pluses, ' '));
        return config.json ? JSON.parse(s) : s;
    } catch(e) {}

@carhartl
Copy link
Owner

carhartl commented Apr 9, 2015

If you set json to true, we expect them to be json parseable... at the moment. In version 2.0 this is going to be handled more gracefully and automatically.

@carhartl carhartl closed this as completed Apr 9, 2015
@carhartl
Copy link
Owner

carhartl commented Apr 9, 2015

See #285

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants