Skip to content
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

should not JSON.parse by default #47

Closed
blackbing opened this issue Nov 16, 2016 · 3 comments
Closed

should not JSON.parse by default #47

blackbing opened this issue Nov 16, 2016 · 3 comments

Comments

@blackbing
Copy link

https://github.com/eXon/react-cookie/blob/master/index.js#L42

By default, it will execute JSON.parse to parse the value. the problem is here. for example.

JSON.parse('99999999999999999'); //-> 100000000000000000
JSON.parse('10209033848396525'); //-> 10209033848396524

it is confused when I just want to set a cookie but getting the wrong value. I think it should not execute JSON.parse by default. Or keep it simple and just leave this transform function to others.

@eXon
Copy link
Collaborator

eXon commented Nov 27, 2016

The problem here is that javascript think it is a number but it is a string. A lot of people are having the same kind of problem.

I think having an automatic stringify / parse is still nice but it should be kept only on objects. The check can be as simple as if the cookie value is starting with a { or [, we're parsing it (unless it throws of course).

Would it solve your problem?

@blackbing
Copy link
Author

blackbing commented Nov 28, 2016 via email

@eXon
Copy link
Collaborator

eXon commented Nov 28, 2016

They are unfortunally saved in string only because it is how cookies work under the hood. Should be fixed :)

@eXon eXon closed this as completed Nov 28, 2016
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

No branches or pull requests

2 participants