tj / node-querystring

querystring parser for node and the browser - supporting nesting (used by Express, Connect, etc)
MIT License
455 stars 66 forks source link

Cannot parse un-scoped property names. #11

Open mhemesath opened 13 years ago

mhemesath commented 13 years ago

I stumbled upon this from a bad input name in my EJS. It seems that querystring isn't expecting un-scoped properties. I don't know what should happen in this case, but the error should probably be handled somehow?

require("qs").parse("[foo]=bar")
TypeError: Cannot read property 'undefined' of undefined
    at parse (/node_modules/qs/lib/querystring.js:50:37)
    at /node_modules/qs/lib/querystring.js:73:9
    at Array.reduce (native)
    at Object.parse (/node_modules/qs/lib/querystring.js:27:6)
    at [object Context]:1:15
    at Interface.<anonymous> (repl.js:171:22)
    at Interface.emit (events.js:64:17)
    at Interface._onLine (readline.js:153:10)
    at Interface._line (readline.js:408:8)
    at Interface._ttyWrite (readline.js:585:14)
tj commented 13 years ago

woah, yeah not sure what that would be, { foo: 'bar' } still?

mhemesath commented 13 years ago

Yeah, that or { '[foo]': 'bar' }.

I don't think it matters too much though, as I doubt anyone is going to intentionally do this. I vote for consistency and just bind the foo property directly to the req.body with the bar value. If this behavior is unexpected, they will quickly see whats going on when they inspect the request anyway.

tj commented 13 years ago

the error message definitely sucks, that's the worst part