Skip to content

Commit

Permalink
v6.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 25, 2020
1 parent 8d1dea2 commit 511e1c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## **6.9.3**
- [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.9.2**
- [Fix] `parse`: Fix parsing array from object with `comma` true (#359)
- [Fix] `parse`: throw a TypeError instead of an Error for bad charset (#349)
Expand Down
32 changes: 23 additions & 9 deletions dist/qs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, 'key');
val = options.decoder(part.slice(pos + 1), defaults.decoder, charset, 'value');
val = maybeMap(
parseArrayValue(part.slice(pos + 1), options),
function (encodedVal) {
return options.decoder(encodedVal, defaults.decoder, charset, 'value');
}
);
}

if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
val = interpretNumericEntities(val);
}

val = parseArrayValue(val, options);

if (part.indexOf('[]=') > -1) {
val = isArray(val) ? [val] : val;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -288,7 +302,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);
}

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.9.2",
"version": "6.9.3",
"repository": {
"type": "git",
"url": "https://github.com/ljharb/qs.git"
Expand Down

0 comments on commit 511e1c9

Please sign in to comment.