| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d64e6e0 commit f8269fe
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -215,7 +215,7 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) { | |||
| 215 | 215 | } | |
| 216 | 216 | ||
| 217 | 217 | // maxKeys <= 0 means that we should not limit keys count | |
| 218 | - if (maxKeys > 0) { | ||
| 218 | + if (maxKeys > 0 && isFinite(maxKeys)) { | ||
| 219 | 219 | qs = qs.split(sep, maxKeys); | |
| 220 | 220 | } else { | |
| 221 | 221 | qs = qs.split(sep); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,55 @@ | |||
| 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); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments