From 23de33968f2b61a784b67308980e31a8d11bf094 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Mon, 16 Jan 2012 16:13:43 +0600 Subject: [PATCH] querystring: fix maxKeys = 0 is ignored --- lib/querystring.js | 7 ++++++- test/simple/test-querystring.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/querystring.js b/lib/querystring.js index f2038f5b21..47e259a320 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -164,7 +164,12 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) { sep = sep || '&'; eq = eq || '='; var obj = {}, - maxKeys = options && options.maxKeys || 1000; + maxKeys = 1000; + + // Handle maxKeys = 0 case + if (options && typeof options.maxKeys === 'number') { + maxKeys = options.maxKeys; + } if (typeof qs !== 'string' || qs.length === 0) { return obj; diff --git a/test/simple/test-querystring.js b/test/simple/test-querystring.js index c0e4ede0f7..bfaf9ae18a 100644 --- a/test/simple/test-querystring.js +++ b/test/simple/test-querystring.js @@ -189,6 +189,22 @@ assert.equal( 1 ); +// Test removing limit +function testUnlimitedKeys() { + var query = {}, + url; + + for (var i = 0; i < 2000; i++) query[i] = i; + + url = qs.stringify(query); + + assert.equal( + Object.keys(qs.parse(url, null, null, { maxKeys: 0 })).length, + 2000 + ); +} +testUnlimitedKeys(); + var b = qs.unescapeBuffer('%d3%f2Ug%1f6v%24%5e%98%cb' + '%0d%ac%a2%2f%9d%eb%d8%a2%e6');