1'use strict'; 2// This test was originally written to test a regression 3// that was introduced by 4// https://github.com/nodejs/node/pull/2288#issuecomment-179543894 5require('../common'); 6 7const assert = require('assert'); 8const parse = require('querystring').parse; 9 10// Taken from express-js/body-parser 11// https://github.com/expressjs/body-parser/blob/ed25264fb494cf0c8bc992b8257092cd4f694d5e/test/urlencoded.js#L636-L651 12function createManyParams(count) { 13 let str = ''; 14 15 if (count === 0) { 16 return str; 17 } 18 19 str += '0=0'; 20 21 for (let i = 1; i < count; i++) { 22 const n = i.toString(36); 23 str += `&${n}=${n}`; 24 } 25 26 return str; 27} 28 29const count = 10000; 30const originalMaxLength = 1000; 31const params = createManyParams(count); 32 33// thealphanerd 34// 27def4f introduced a change to parse that would cause Infinity 35// to be passed to String.prototype.split as an argument for limit 36// In this instance split will always return an empty array 37// this test confirms that the output of parse is the expected length 38// when passed Infinity as the argument for maxKeys 39const resultInfinity = parse(params, undefined, undefined, { 40 maxKeys: Infinity 41}); 42const resultNaN = parse(params, undefined, undefined, { 43 maxKeys: NaN 44}); 45const resultInfinityString = parse(params, undefined, undefined, { 46 maxKeys: 'Infinity' 47}); 48const resultNaNString = parse(params, undefined, undefined, { 49 maxKeys: 'NaN' 50}); 51 52// Non Finite maxKeys should return the length of input 53assert.strictEqual(Object.keys(resultInfinity).length, count); 54assert.strictEqual(Object.keys(resultNaN).length, count); 55// Strings maxKeys should return the maxLength 56// defined by parses internals 57assert.strictEqual(Object.keys(resultInfinityString).length, originalMaxLength); 58assert.strictEqual(Object.keys(resultNaNString).length, originalMaxLength); 59