diff --git a/CHANGELOG.md b/CHANGELOG.md index f0d0bf9b..6ccd56d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## **6.0.4** +- [Fix] follow `allowPrototypes` option during merge (#201, #200) +- [Fix] chmod a-x +- [Fix] support keys starting with brackets (#202, #200) +- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds + ## **6.0.3** - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties - [Fix] Restore `dist` directory; will be removed in v7 (#148) diff --git a/bower.json b/bower.json index 8b21420a..44f05064 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,6 @@ { "name": "qs", "main": "dist/qs.js", - "version": "5.2.0", "homepage": "https://github.com/hapijs/qs", "authors": [ "Nathan LaFreniere " diff --git a/component.json b/component.json index 90758a9b..a97705c7 100644 --- a/component.json +++ b/component.json @@ -2,7 +2,7 @@ "name": "qs", "repository": "hapijs/qs", "description": "query-string parser / stringifier with nesting support", - "version": "6.0.3", + "version": "6.0.4", "keywords": ["querystring", "query", "parser"], "main": "lib/index.js", "scripts": [ diff --git a/dist/qs.js b/dist/qs.js index 1bf41da7..646d91a3 100644 --- a/dist/qs.js +++ b/dist/qs.js @@ -25,6 +25,8 @@ var internals = { allowDots: false }; +var has = Object.prototype.hasOwnProperty; + internals.parseValues = function (str, options) { var obj = {}; var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit); @@ -43,7 +45,7 @@ internals.parseValues = function (str, options) { var key = Utils.decode(part.slice(0, pos)); var val = Utils.decode(part.slice(pos + 1)); - if (Object.prototype.hasOwnProperty.call(obj, key)) { + if (has.call(obj, key)) { obj[key] = [].concat(obj[key]).concat(val); } else { obj[key] = val; @@ -96,26 +98,27 @@ internals.parseKeys = function (givenKey, val, options) { // The regex chunks - var parent = /^([^[]*)/; + var brackets = /(\[[^[\]]*])/; var child = /(\[[^[\]]*])/g; // Get the parent - var segment = parent.exec(key); + var segment = brackets.exec(key); + var parent = segment ? key.slice(0, segment.index) : key; // Stash the parent if it exists var keys = []; - if (segment[1]) { + if (parent) { // If we aren't using plain objects, optionally prefix keys // that would overwrite object prototype properties - if (!options.plainObjects && Object.prototype.hasOwnProperty(segment[1])) { + if (!options.plainObjects && has.call(Object.prototype, parent)) { if (!options.allowPrototypes) { return; } } - keys.push(segment[1]); + keys.push(parent); } // Loop through children appending to the array until we hit depth @@ -123,7 +126,7 @@ internals.parseKeys = function (givenKey, val, options) { var i = 0; while ((segment = child.exec(key)) !== null && i < options.depth) { i += 1; - if (!options.plainObjects && Object.prototype.hasOwnProperty.call(Object.prototype, segment[1].slice(1, -1))) { + if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) { if (!options.allowPrototypes) { return; } @@ -319,6 +322,8 @@ var hexTable = (function () { return array; }()); +var has = Object.prototype.hasOwnProperty; + exports.arrayToObject = function (source, options) { var obj = options.plainObjects ? Object.create(null) : {}; for (var i = 0; i < source.length; ++i) { @@ -339,7 +344,9 @@ exports.merge = function (target, source, options) { if (Array.isArray(target)) { target.push(source); } else if (typeof target === 'object') { - target[source] = true; + if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) { + target[source] = true; + } } else { return [target, source]; } @@ -359,7 +366,7 @@ exports.merge = function (target, source, options) { return Object.keys(source).reduce(function (acc, key) { var value = source[key]; - if (Object.prototype.hasOwnProperty.call(acc, key)) { + if (has.call(acc, key)) { acc[key] = exports.merge(acc[key], value, options); } else { acc[key] = value; diff --git a/package.json b/package.json index 377dabef..4ebd91aa 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "qs", "description": "A querystring parser that supports nesting and arrays, with a depth limit", "homepage": "https://github.com/ljharb/qs", - "version": "6.0.3", + "version": "6.0.4", "repository": { "type": "git", "url": "https://github.com/ljharb/qs.git" @@ -34,7 +34,8 @@ "evalmd": "^0.0.16" }, "scripts": { - "test": "parallelshell 'npm run readme' 'npm run lint' 'npm run coverage'", + "pretest": "npm run lint && npm run readme", + "test": "npm run coverage", "tests-only": "node test", "readme": "evalmd README.md", "lint": "eslint lib/*.js text/*.js",