From 43a604b7847e56bba49d0ce3e222fe89569354d8 Mon Sep 17 00:00:00 2001
From: Raymond Feng <raymond@strongloop.com>
Date: Sun, 3 Aug 2014 22:59:55 -0700
Subject: [PATCH] Make sure nesting arrays are compacted to avoid memory
overflow
See https://github.com/visionmedia/node-querystring/issues/104
---
index.js | 4 +++-
test/parse.js | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/index.js b/index.js
index 426017b..311ce62 100644
--- a/index.js
+++ b/index.js
@@ -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]));
}
}
diff --git a/test/parse.js b/test/parse.js
index 4fed7b9..bb69148 100644
--- a/test/parse.js
+++ b/test/parse.js
@@ -159,6 +159,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');