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

Make sure nesting arrays are compacted to avoid memory overflow #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ function compact(obj) {

for (var i in obj) {
if (hasOwnProperty.call(obj, i)) {
ret.push(obj[i]);
// We need to compact the nesting array too
// See https://github.com/visionmedia/node-querystring/issues/104
ret.push(compact(obj[i]));
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ describe('qs.parse()', function(){
expect(q['a'].length).to.eql(2);
expect(q).to.eql({ a: ['2', '1'] });
})

it('should not create big nesting arrays of null objects', function () {
var q = qs.parse('a[0][999999999]=1');
console.log(q.a[0]);
expect(q['a'].length).to.eql(1);
expect(q['a'][0]).to.eql(['1']);
})

it('should not be able to override prototypes', function(){
var obj = qs.parse('toString=bad&bad[toString]=bad&constructor=bad');
Expand Down