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

JSON.parse can be dangerous #84

Open
Jbarget opened this issue Dec 8, 2017 · 0 comments
Open

JSON.parse can be dangerous #84

Jbarget opened this issue Dec 8, 2017 · 0 comments

Comments

@Jbarget
Copy link

Jbarget commented Dec 8, 2017

https://github.com/fac-12/BudgetPlanner/blob/master/public/index.js#L22

If the xhr.responseText is a string here, JSON.parse will fail with Uncaught SyntaxError: Unexpected token a in JSON at position 0, which will break things.

So its good to 'wrap' JSON.parse in a try/catch block, see below for an example:
https://stackoverflow.com/questions/29797946/handling-bad-json-parse-in-node-safely

PS. please share this with the whole cohort as its something thats valuable to know

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

1 participant