Permalink
Browse files

querystring: fix maxKeys = 0 is ignored

  • Loading branch information...
1 parent 664eb8a commit 7eed288312e9e1084c4d1473bdacacf299881f78 @indutny committed Jan 16, 2012
Showing with 22 additions and 1 deletion.
  1. +6 −1 lib/querystring.js
  2. +16 −0 test/simple/test-querystring.js
View
@@ -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;
@@ -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');

0 comments on commit 7eed288

Please sign in to comment.