Skip to content

Commit

Permalink
v6.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 6, 2017
1 parent eb2e3a5 commit 1fb74cb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## **6.2.3**
- [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.2.2**
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties

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.2.2",
"version": "6.2.3",
"keywords": ["querystring", "query", "parser"],
"main": "lib/index.js",
"scripts": [
Expand Down
21 changes: 13 additions & 8 deletions dist/qs.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,31 @@ var parseKeys = function parseKeys(givenKey, val, options) {
}

// Transform dot notation to bracket notation
var key = options.allowDots ? givenKey.replace(/\.([^\.\[]+)/g, '[$1]') : givenKey;
var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;

// 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 && has.call(Object.prototype, 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
Expand Down Expand Up @@ -328,6 +329,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 @@ -348,7 +351,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 @@ -368,7 +373,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
4 changes: 3 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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 Down Expand Up @@ -51,7 +53,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
2 changes: 1 addition & 1 deletion 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.2.2",
"version": "6.2.3",
"repository": {
"type": "git",
"url": "https://github.com/ljharb/qs.git"
Expand Down

0 comments on commit 1fb74cb

Please sign in to comment.