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

Encode string values as strings #29

Closed
wants to merge 2 commits into from
Closed

Conversation

tmair
Copy link

@tmair tmair commented Aug 19, 2014

When a cookie is read that contains a string constisting of digits only, the call of JSON.parse will parse the String as a Number. If the number is larger than the JavaScript Number type the returned value is interpolated.

Example:

ipCookie('example', '545654545664564564564554554545');
console.log(ipCookie('example')); // 5.4565454566456454e+29

@tmair
Copy link
Author

tmair commented Aug 19, 2014

The problem with the proposed changes is, that it is not possible to store any value without quotes in cookies. So maybe the pull request is obsolete, but the issue with numeric strings should be mentioned in the documentation.

@ivpusic
Copy link
Owner

ivpusic commented Aug 19, 2014

I will update readme. Thank you!

@ivpusic ivpusic closed this Aug 19, 2014
@that70schris
Copy link

@ivpusic, instead of changing the way cookies are set, you could add a check for isNaN(value) before trying to JSON.parse(value)

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

Successfully merging this pull request may close these issues.

None yet

3 participants