diff --git a/lib/parse.js b/lib/parse.js index f0c2a080..3283fb11 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -3,6 +3,7 @@ var utils = require('./utils'); var has = Object.prototype.hasOwnProperty; +var isArray = Array.isArray; var defaults = { allowDots: false, @@ -87,6 +88,10 @@ var parseValues = function parseQueryStringValues(str, options) { val = val.split(','); } + if (part.indexOf('[]=') > -1) { + val = isArray(val) ? [val] : val; + } + if (has.call(obj, key)) { obj[key] = utils.combine(obj[key], val); } else { diff --git a/test/parse.js b/test/parse.js index 1563b5f6..101e5160 100644 --- a/test/parse.js +++ b/test/parse.js @@ -414,6 +414,15 @@ test('parse()', function (t) { st.end(); }); + t.test('parses brackets holds array of arrays when having two parts of strings with comma as array divider', function (st) { + st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=4,5,6', { comma: true }), { foo: [['1', '2', '3'], ['4', '5', '6']] }); + st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=', { comma: true }), { foo: [['1', '2', '3'], ''] }); + st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=,', { comma: true }), { foo: [['1', '2', '3'], ['', '']] }); + st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=a', { comma: true }), { foo: [['1', '2', '3'], 'a'] }); + + st.end(); + }); + t.test('parses an object in dot notation', function (st) { var input = { 'user.name': { 'pop[bob]': 3 },