sandy98 / node-simple-router

Yet another minimalistic router for node.js
node-simple-router.herokuapp.com
MIT License
36 stars 18 forks source link

JSON.parse in body parser fails silently when string has unescaped double quotes #20

Open rahulreddy opened 9 years ago

rahulreddy commented 9 years ago

I ran into this issue when using a route to upload a file NSR was stripping out double quotes after parsing the body into request.post. After digging through, I found out that JSON.parse returns a string with the quotes stripped (it should either throw an error or return an object) even though the input is just a string. Please try the code below in console to replicate the error.

var str = '"hello"';
console.log(JSON.parse(str));
// returns hello removing the quotes

var str = '"hello';
console.log(JSON.parse(str));
// throws SynraxError exception as it should