Skip to content

Commit

Permalink
avoid breaking change by handling comma separation outside of decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinus95 authored and ljharb committed Mar 22, 2020
1 parent 756f1e1 commit 8aa59b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 9 additions & 1 deletion lib/parse.js
Expand Up @@ -85,7 +85,15 @@ 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', options.comma);
var encodedVal = part.slice(pos + 1);
if (options.comma && encodedVal.indexOf(',') !== -1) {
val = encodedVal.split(',')
.map(function (encodedFragment) {
return options.decoder(encodedFragment, defaults.decoder, charset, 'value');
});
} else {
val = options.decoder(encodedVal, defaults.decoder, charset, 'value');
}
}

if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
Expand Down
7 changes: 1 addition & 6 deletions lib/utils.js
Expand Up @@ -106,19 +106,14 @@ var assign = function assignSingleSource(target, source) {
}, target);
};

var decode = function (str, decoder, charset, key, comma) {
var decode = function (str, decoder, charset) {
var strWithoutPlus = str.replace(/\+/g, ' ');
if (charset === 'iso-8859-1') {
// unescape never throws, no try...catch needed:
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
}
// utf-8
try {
if (comma && strWithoutPlus.indexOf(',') > -1) {
return strWithoutPlus.split(',').map(function (withoutPlusItem) {
return decodeURIComponent(withoutPlusItem);
});
}
return decodeURIComponent(strWithoutPlus);
} catch (e) {
return strWithoutPlus;
Expand Down

0 comments on commit 8aa59b6

Please sign in to comment.