Skip to content

Commit

Permalink
v6.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 24, 2020
1 parent 85a3d32 commit 47247f4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,16 @@
## **6.8.1**
- [Fix] `parse`: Fix parsing array from object with `comma` true (#359)
- [Fix] `parse`: throw a TypeError instead of an Error for bad charset (#349)
- [Fix] `parse`: with comma true, handle field that holds an array of arrays (#335)
- [fix] `parse`: with comma true, do not split non-string values (#334)
- [meta] add tidelift marketing copy
- [meta] add `funding` field
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`, `safe-publish-latest`, `evalmd`, `has-symbols`, `iconv-lite`, `mkdirp`, `object-inspect`
- [Tests] `parse`: add passing `arrayFormat` tests
- [Tests] use shared travis-ci configs
- [Tests] `Buffer.from` in node v5.0-v5.9 and v4.0-v4.4 requires a TypedArray
- [actions] add automatic rebasing / merge commit blocking

## **6.8.0**
- [New] add `depth=false` to preserve the original key; [Fix] `depth=0` should preserve the original key (#326)
- [New] [Fix] stringify symbols and bigints
Expand Down
43 changes: 27 additions & 16 deletions dist/qs.js
Expand Up @@ -45,6 +45,7 @@ module.exports = {
var utils = require('./utils');

var has = Object.prototype.hasOwnProperty;
var isArray = Array.isArray;

var defaults = {
allowDots: false,
Expand All @@ -70,6 +71,14 @@ var interpretNumericEntities = function (str) {
});
};

var parseArrayValue = function (val, options) {
if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
return val.split(',');
}

return 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 @@ -125,8 +134,10 @@ var parseValues = function parseQueryStringValues(str, options) {
val = interpretNumericEntities(val);
}

if (val && options.comma && val.indexOf(',') > -1) {
val = val.split(',');
val = parseArrayValue(val, options);

if (part.indexOf('[]=') > -1) {
val = isArray(val) ? [val] : val;
}

if (has.call(obj, key)) {
Expand All @@ -140,7 +151,7 @@ var parseValues = function parseQueryStringValues(str, options) {
};

var parseObject = function (chain, val, options) {
var leaf = val;
var leaf = parseArrayValue(val, options);

for (var i = chain.length - 1; i >= 0; --i) {
var obj;
Expand Down Expand Up @@ -238,7 +249,7 @@ var normalizeParseOptions = function normalizeParseOptions(opts) {
}

if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined');
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
}
var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;

Expand Down Expand Up @@ -292,14 +303,14 @@ var formats = require('./formats');
var has = Object.prototype.hasOwnProperty;

var arrayPrefixGenerators = {
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
brackets: function brackets(prefix) {
return prefix + '[]';
},
comma: 'comma',
indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
indices: function indices(prefix, key) {
return prefix + '[' + key + ']';
},
repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
repeat: function repeat(prefix) {
return prefix;
}
};
Expand All @@ -326,22 +337,22 @@ var defaults = {
formatter: formats.formatters[defaultFormat],
// deprecated
indices: false,
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
serializeDate: function serializeDate(date) {
return toISO.call(date);
},
skipNulls: false,
strictNullHandling: false
};

var isNonNullishPrimitive = function isNonNullishPrimitive(v) { // eslint-disable-line func-name-matching
var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
return typeof v === 'string'
|| typeof v === 'number'
|| typeof v === 'boolean'
|| typeof v === 'symbol'
|| typeof v === 'bigint'; // eslint-disable-line valid-typeof
};

var stringify = function stringify( // eslint-disable-line func-name-matching
var stringify = function stringify(
object,
prefix,
generateArrayPrefix,
Expand Down Expand Up @@ -620,7 +631,7 @@ var merge = function merge(target, source, options) {
target.push(source);
} else if (target && typeof target === 'object') {
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
target[source] = true;
target[source] = true; // eslint-disable-line no-param-reassign
}
} else {
return [target, source];
Expand All @@ -643,12 +654,12 @@ var merge = function merge(target, source, options) {
if (has.call(target, i)) {
var targetItem = target[i];
if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
target[i] = merge(targetItem, item, options);
target[i] = merge(targetItem, item, options); // eslint-disable-line no-param-reassign
} else {
target.push(item);
}
} else {
target[i] = item;
target[i] = item; // eslint-disable-line no-param-reassign
}
});
return target;
Expand All @@ -658,17 +669,17 @@ var merge = function merge(target, source, options) {
var value = source[key];

if (has.call(acc, key)) {
acc[key] = merge(acc[key], value, options);
acc[key] = merge(acc[key], value, options); // eslint-disable-line no-param-reassign
} else {
acc[key] = value;
acc[key] = value; // eslint-disable-line no-param-reassign
}
return acc;
}, mergeTarget);
};

var assign = function assignSingleSource(target, source) {
return Object.keys(source).reduce(function (acc, key) {
acc[key] = source[key];
acc[key] = source[key]; // eslint-disable-line no-param-reassign
return acc;
}, target);
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
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.8.0",
"version": "6.8.1",
"repository": {
"type": "git",
"url": "https://github.com/ljharb/qs.git"
Expand Down

0 comments on commit 47247f4

Please sign in to comment.