diff --git a/lib/parse.js b/lib/parse.js index 47570132..4abc1a70 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -53,13 +53,15 @@ var parseObject = function (chain, val, options) { var obj; var root = chain[i]; - if (root === '[]') { + if (root === '[]' && options.parseArrays) { obj = [].concat(leaf); } else { obj = options.plainObjects ? Object.create(null) : {}; var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root; var index = parseInt(cleanRoot, 10); - if ( + if (!options.parseArrays && cleanRoot === '') { + obj = { 0: leaf }; + } else if ( !isNaN(index) && root !== cleanRoot && String(index) === cleanRoot diff --git a/package.json b/package.json index 2c654900..ed6ccf06 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "test": "npm run --silent coverage", "tests-only": "node test", "readme": "evalmd README.md", - "prelint": "editorconfig-tools check * lib/* test/*", + "postlint": "editorconfig-tools check * lib/* test/*", "lint": "eslint lib/*.js test/*.js", "coverage": "covert test", "dist": "mkdirp dist && browserify --standalone Qs lib/index.js > dist/qs.js" diff --git a/test/parse.js b/test/parse.js index 0f8fe457..c6d0fbfe 100644 --- a/test/parse.js +++ b/test/parse.js @@ -302,7 +302,14 @@ test('parse()', function (t) { }); t.test('allows disabling array parsing', function (st) { - st.deepEqual(qs.parse('a[0]=b&a[1]=c', { parseArrays: false }), { a: { 0: 'b', 1: 'c' } }); + var indices = qs.parse('a[0]=b&a[1]=c', { parseArrays: false }); + st.deepEqual(indices, { a: { 0: 'b', 1: 'c' } }); + st.equal(Array.isArray(indices.a), false, 'parseArrays:false, indices case is not an array'); + + var emptyBrackets = qs.parse('a[]=b', { parseArrays: false }); + st.deepEqual(emptyBrackets, { a: { 0: 'b' } }); + st.equal(Array.isArray(emptyBrackets.a), false, 'parseArrays:false, empty brackets case is not an array'); + st.end(); });