From bf93c5719c88e4c7ace17d747c62844988a65018 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 25 Mar 2020 12:10:46 -0700 Subject: [PATCH] v6.7.2 --- CHANGELOG.md | 4 ++++ dist/qs.js | 32 +++++++++++++++++++++++--------- package.json | 2 +- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee2f773a..47e0e93a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## **6.7.2** +- [Fix] proper comma parsing of URL-encoded commas (#361) +- [Fix] parses comma delimited array while having percent-encoded comma treated as normal text (#336) + ## **6.7.1** - [Fix] `parse`: Fix parsing array from object with `comma` true (#359) - [Fix] `parse`: with comma true, handle field that holds an array of arrays (#335) diff --git a/dist/qs.js b/dist/qs.js index 4986a7b8..48bf862f 100644 --- a/dist/qs.js +++ b/dist/qs.js @@ -79,6 +79,17 @@ var parseArrayValue = function (val, options) { return val; }; +var maybeMap = function maybeMap(val, fn) { + if (isArray(val)) { + var mapped = []; + for (var i = 0; i < val.length; i += 1) { + mapped.push(fn(val[i])); + } + return mapped; + } + return fn(val); +}; + // This is what browsers will submit when the ✓ character occurs in an // application/x-www-form-urlencoded body and the encoding of the page containing // the form is iso-8859-1, or when the submitted form has an accept-charset @@ -127,15 +138,18 @@ var parseValues = function parseQueryStringValues(str, options) { val = options.strictNullHandling ? null : ''; } else { key = options.decoder(part.slice(0, pos), defaults.decoder, charset); - val = options.decoder(part.slice(pos + 1), defaults.decoder, charset); + val = maybeMap( + parseArrayValue(part.slice(pos + 1), options), + function (encodedVal) { + return options.decoder(encodedVal, defaults.decoder, charset); + } + ); } if (val && options.interpretNumericEntities && charset === 'iso-8859-1') { val = interpretNumericEntities(val); } - val = parseArrayValue(val, options); - if (part.indexOf('[]=') > -1) { val = isArray(val) ? [val] : val; } @@ -150,8 +164,8 @@ var parseValues = function parseQueryStringValues(str, options) { return obj; }; -var parseObject = function (chain, val, options) { - var leaf = parseArrayValue(val, options); +var parseObject = function (chain, val, options, valuesParsed) { + var leaf = valuesParsed ? val : parseArrayValue(val, options); for (var i = chain.length - 1; i >= 0; --i) { var obj; @@ -179,13 +193,13 @@ var parseObject = function (chain, val, options) { } } - leaf = obj; + leaf = obj; // eslint-disable-line no-param-reassign } return leaf; }; -var parseKeys = function parseQueryStringKeys(givenKey, val, options) { +var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) { if (!givenKey) { return; } @@ -236,7 +250,7 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) { keys.push('[' + key.slice(segment.index) + ']'); } - return parseObject(keys, val, options); + return parseObject(keys, val, options, valuesParsed); }; var normalizeParseOptions = function normalizeParseOptions(opts) { @@ -287,7 +301,7 @@ module.exports = function (str, opts) { var keys = Object.keys(tempObj); for (var i = 0; i < keys.length; ++i) { var key = keys[i]; - var newObj = parseKeys(key, tempObj[key], options); + var newObj = parseKeys(key, tempObj[key], options, typeof str === 'string'); obj = utils.merge(obj, newObj, options); } diff --git a/package.json b/package.json index 3a4b587d..777ffa40 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.7.1", + "version": "6.7.2", "repository": { "type": "git", "url": "https://github.com/ljharb/qs.git"