Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
querystring: fix maxKeys = 0 is ignored
  • Loading branch information
indutny committed Jan 16, 2012
1 parent f1678bf commit 23de339
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/querystring.js
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions test/simple/test-querystring.js
Expand Up @@ -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');
Expand Down

0 comments on commit 23de339

Please sign in to comment.