Closed abecciu closed 11 years ago
@visionmedia any feedback on this?
hmmm they're sparse internally, for example qs.parse('foo[100000000000000000000000000000000000000000000]=1')
wont exhaust memory, however for iteration and console.log()
this is obviously not ideal :D haha I'll check out the fix
instead of altering the already super messy functions a bunch we could wrap the parseObject response with something like:
function sparse(obj) {
if (Array.isArray(obj)) {
var ret = [];
for (var i in obj) ret.push(obj[i]);
return ret;
}
for (var key in obj) {
obj[key] = sparse(obj[key]);
}
return obj;
}
and make sure it recurses properly
@visionmedia sounds like a very clean solution. However, if I understand correctly, you'd have to iterate over potentially very long arrays. And that consumes a lot of cpu time.
@abecciu for/in
just iterates the hash keys
Oh didn't know that it works like that even in arrays. Great then! I'll make the change.
@visionmedia done! Way cleaner now. Thanks for the feedback! :)
merged! thanks man
So. This PR breaks my production code when I try to send array which starts with non-zero index and expect what non-defined array elements will be undefined
. How should I send empty array element to server now? Of course, I can send JSON instead of form data but this behavior of querystring library was not expected.
This fixes a serious bug. Someone hitting an app with a param like
a[999999999]=1
could make a node process crash by running out memory very quickly.Example: