Browse Source

querystring: fix maxKeys = 0 is ignored

v0.7.4-release
Fedor Indutny 13 years ago
parent
commit
23de33968f
  1. 7
      lib/querystring.js
  2. 16
      test/simple/test-querystring.js

7
lib/querystring.js

@ -164,7 +164,12 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
sep = sep || '&'; sep = sep || '&';
eq = eq || '='; eq = eq || '=';
var obj = {}, 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) { if (typeof qs !== 'string' || qs.length === 0) {
return obj; return obj;

16
test/simple/test-querystring.js

@ -189,6 +189,22 @@ assert.equal(
1 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' + var b = qs.unescapeBuffer('%d3%f2Ug%1f6v%24%5e%98%cb' +
'%0d%ac%a2%2f%9d%eb%d8%a2%e6'); '%0d%ac%a2%2f%9d%eb%d8%a2%e6');

Loading…
Cancel
Save