Skip to content

Commit

Permalink
v6.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 6, 2017
1 parent 2e1c659 commit 10233c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "qs",
"main": "dist/qs.js",
"version": "5.2.0",
"homepage": "https://github.com/hapijs/qs",
"authors": [
"Nathan LaFreniere <quitlahok@gmail.com>"
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
25 changes: 16 additions & 9 deletions dist/qs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -96,34 +98,35 @@ 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

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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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];
}
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 10233c9

Please # to comment.