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