• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/*
11taken from express-js/body-parser
12https://github.com/expressjs/body-parser/
13blob/ed25264fb494cf0c8bc992b8257092cd4f694d5e/test/urlencoded.js#L636-L651
14*/
15function createManyParams(count) {
16  let str = '';
17
18  if (count === 0) {
19    return str;
20  }
21
22  str += '0=0';
23
24  for (let i = 1; i < count; i++) {
25    const n = i.toString(36);
26    str += `&${n}=${n}`;
27  }
28
29  return str;
30}
31
32const count = 10000;
33const originalMaxLength = 1000;
34const params = createManyParams(count);
35
36// thealphanerd
37// 27def4f introduced a change to parse that would cause Infinity
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
42const resultInfinity = parse(params, undefined, undefined, {
43  maxKeys: Infinity
44});
45const resultNaN = parse(params, undefined, undefined, {
46  maxKeys: NaN
47});
48const resultInfinityString = parse(params, undefined, undefined, {
49  maxKeys: 'Infinity'
50});
51const resultNaNString = parse(params, undefined, undefined, {
52  maxKeys: 'NaN'
53});
54
55// Non Finite maxKeys should return the length of input
56assert.strictEqual(Object.keys(resultInfinity).length, count);
57assert.strictEqual(Object.keys(resultNaN).length, count);
58// Strings maxKeys should return the maxLength
59// defined by parses internals
60assert.strictEqual(Object.keys(resultInfinityString).length, originalMaxLength);
61assert.strictEqual(Object.keys(resultNaNString).length, originalMaxLength);
62