diff --git a/index.js b/index.js index 7a9ffcaf..d19e1381 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,7 @@ function parserForArrayFormat(options) { case 'comma': return (key, value, accumulator) => { const isArray = typeof value === 'string' && value.split('').indexOf(',') > -1; - const newValue = isArray ? value.split(',') : value; + const newValue = isArray ? value.split(',').map(item => decode(item, options)) : value === null ? value : decode(value, options); accumulator[key] = newValue; }; @@ -220,7 +220,7 @@ function parse(input, options) { // Missing `=` should be `null`: // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters - value = value === undefined ? null : decode(value, options); + value = value === undefined ? null : options.arrayFormat === 'comma' ? value : decode(value, options); formatter(decode(key, options), value, ret); } diff --git a/test/parse.js b/test/parse.js index f75a7456..b2f4da02 100644 --- a/test/parse.js +++ b/test/parse.js @@ -284,3 +284,12 @@ test('parseNumbers and parseBooleans can work with arrayFormat at the same time' t.deepEqual(queryString.parse('foo=true,false&bar=1,2', {parseNumbers: true, parseBooleans: true, arrayFormat: 'comma'}), {foo: [true, false], bar: [1, 2]}); t.deepEqual(queryString.parse('foo[0]=true&foo[1]=false&bar[0]=1&bar[1]=2', {parseNumbers: true, parseBooleans: true, arrayFormat: 'index'}), {foo: [true, false], bar: [1, 2]}); }); + +test('query strings having comma encoded and format option as `comma`', t => { + t.deepEqual(queryString.parse('foo=zero%2Cone,two%2Cthree', {arrayFormat: 'comma'}), { + foo: [ + 'zero,one', + 'two,three' + ] + }); +});