From c7f87b8d2eedd377f6ace065655201f51bee6334 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 5 Mar 2017 22:31:15 -0800 Subject: [PATCH] v6.4.0 --- CHANGELOG.md | 9 +++++++++ component.json | 2 +- dist/qs.js | 38 ++++++++++++++++++++++++-------------- package.json | 2 +- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bcb0669..85e69b0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## **6.4.0** +- [New] `qs.stringify`: add `encodeValuesOnly` option +- [Fix] follow `allowPrototypes` option during merge (#201, #201) +- [Fix] support keys starting with brackets (#202, #200) +- [Fix] chmod a-x +- [Dev Deps] update `eslint` +- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds +- [eslint] reduce warnings + ## **6.3.1** - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties (thanks, @snyk!) - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `browserify`, `iconv-lite`, `qs-iconv`, `tape` diff --git a/component.json b/component.json index dabd1d48..d5ad2921 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.3.1", + "version": "6.4.0", "keywords": ["querystring", "query", "parser"], "main": "lib/index.js", "scripts": [ diff --git a/dist/qs.js b/dist/qs.js index 3d2c211f..2d0d63ff 100644 --- a/dist/qs.js +++ b/dist/qs.js @@ -118,26 +118,27 @@ var parseKeys = function parseQueryStringKeys(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 && 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 @@ -223,6 +224,7 @@ var defaults = { delimiter: '&', encode: true, encoder: utils.encode, + encodeValuesOnly: false, serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching return toISO.call(date); }, @@ -241,7 +243,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching sort, allowDots, serializeDate, - formatter + formatter, + encodeValuesOnly ) { var obj = object; if (typeof filter === 'function') { @@ -250,7 +253,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching obj = serializeDate(obj); } else if (obj === null) { if (strictNullHandling) { - return encoder ? encoder(prefix) : prefix; + return encoder && !encodeValuesOnly ? encoder(prefix) : prefix; } obj = ''; @@ -258,7 +261,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) { if (encoder) { - return [formatter(encoder(prefix)) + '=' + formatter(encoder(obj))]; + var keyValue = encodeValuesOnly ? prefix : encoder(prefix); + return [formatter(keyValue) + '=' + formatter(encoder(obj))]; } return [formatter(prefix) + '=' + formatter(String(obj))]; } @@ -296,7 +300,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching sort, allowDots, serializeDate, - formatter + formatter, + encodeValuesOnly )); } else { values = values.concat(stringify( @@ -310,7 +315,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching sort, allowDots, serializeDate, - formatter + formatter, + encodeValuesOnly )); } } @@ -330,10 +336,11 @@ module.exports = function (object, opts) { var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling; var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls; var encode = typeof options.encode === 'boolean' ? options.encode : defaults.encode; - var encoder = encode ? (typeof options.encoder === 'function' ? options.encoder : defaults.encoder) : null; + var encoder = typeof options.encoder === 'function' ? options.encoder : defaults.encoder; var sort = typeof options.sort === 'function' ? options.sort : null; var allowDots = typeof options.allowDots === 'undefined' ? false : options.allowDots; var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate; + var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly; if (typeof options.format === 'undefined') { options.format = formats.default; } else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) { @@ -389,12 +396,13 @@ module.exports = function (object, opts) { generateArrayPrefix, strictNullHandling, skipNulls, - encoder, + encode ? encoder : null, filter, sort, allowDots, serializeDate, - formatter + formatter, + encodeValuesOnly )); } @@ -435,7 +443,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]; } diff --git a/package.json b/package.json index 228769a8..de4f7371 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.3.1", + "version": "6.4.0", "repository": { "type": "git", "url": "https://github.com/ljharb/qs.git"