Skip to content

Commit f92ddb5

Browse files
committed
v6.10.3
1 parent d9e9529 commit f92ddb5

File tree

4 files changed

+81
-32
lines changed

4 files changed

+81
-32
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## **6.10.3**
2+
- [Fix] `parse`: ignore `__proto__` keys (#428)
3+
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
4+
- [actions] reuse common workflows
5+
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `object-inspect`, `tape`
6+
17
## **6.10.2**
28
- [Fix] `stringify`: actually fix cyclic references (#426)
39
- [Fix] `stringify`: avoid encoding arrayformat comma when `encodeValuesOnly = true` (#424)

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "qs",
33
"repository": "hapijs/qs",
44
"description": "query-string parser / stringifier with nesting support",
5-
"version": "6.5.0",
5+
"version": "6.10.3",
66
"keywords": ["querystring", "query", "parser"],
77
"main": "lib/index.js",
88
"scripts": [

dist/qs.js

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ var parseObject = function (chain, val, options, valuesParsed) {
175175
) {
176176
obj = [];
177177
obj[index] = leaf;
178-
} else {
178+
} else if (cleanRoot !== '__proto__') {
179179
obj[cleanRoot] = leaf;
180180
}
181181
}
@@ -384,7 +384,7 @@ var stringify = function stringify(
384384
var tmpSc = sideChannel;
385385
var step = 0;
386386
var findFlag = false;
387-
while ((tmpSc = tmpSc.get(sentinel)) !== undefined && !findFlag) {
387+
while ((tmpSc = tmpSc.get(sentinel)) !== void undefined && !findFlag) {
388388
// Where object last appeared in the ref tree
389389
var pos = tmpSc.get(object);
390390
step += 1;
@@ -446,7 +446,7 @@ var stringify = function stringify(
446446
var objKeys;
447447
if (generateArrayPrefix === 'comma' && isArray(obj)) {
448448
// we need to join elements in
449-
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : undefined }];
449+
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
450450
} else if (isArray(filter)) {
451451
objKeys = filter;
452452
} else {
@@ -456,7 +456,7 @@ var stringify = function stringify(
456456

457457
for (var j = 0; j < objKeys.length; ++j) {
458458
var key = objKeys[j];
459-
var value = typeof key === 'object' && key.value !== undefined ? key.value : obj[key];
459+
var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];
460460

461461
if (skipNulls && value === null) {
462462
continue;
@@ -496,7 +496,7 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
496496
return defaults;
497497
}
498498

499-
if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') {
499+
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
500500
throw new TypeError('Encoder has to be a function.');
501501
}
502502

@@ -1419,11 +1419,24 @@ var weakRefDeref = hasWeakRef ? WeakRef.prototype.deref : null;
14191419
var booleanValueOf = Boolean.prototype.valueOf;
14201420
var objectToString = Object.prototype.toString;
14211421
var functionToString = Function.prototype.toString;
1422-
var match = String.prototype.match;
1422+
var $match = String.prototype.match;
1423+
var $slice = String.prototype.slice;
1424+
var $replace = String.prototype.replace;
1425+
var $toUpperCase = String.prototype.toUpperCase;
1426+
var $toLowerCase = String.prototype.toLowerCase;
1427+
var $test = RegExp.prototype.test;
1428+
var $concat = Array.prototype.concat;
1429+
var $join = Array.prototype.join;
1430+
var $arrSlice = Array.prototype.slice;
1431+
var $floor = Math.floor;
14231432
var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null;
14241433
var gOPS = Object.getOwnPropertySymbols;
14251434
var symToString = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? Symbol.prototype.toString : null;
14261435
var hasShammedSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'object';
1436+
// ie, `has-tostringtag/shams
1437+
var toStringTag = typeof Symbol === 'function' && Symbol.toStringTag && (typeof Symbol.toStringTag === hasShammedSymbols ? 'object' : 'symbol')
1438+
? Symbol.toStringTag
1439+
: null;
14271440
var isEnumerable = Object.prototype.propertyIsEnumerable;
14281441

14291442
var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPrototypeOf) || (
@@ -1434,9 +1447,30 @@ var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPr
14341447
: null
14351448
);
14361449

1450+
function addNumericSeparator(num, str) {
1451+
if (
1452+
num === Infinity
1453+
|| num === -Infinity
1454+
|| num !== num
1455+
|| (num && num > -1000 && num < 1000)
1456+
|| $test.call(/e/, str)
1457+
) {
1458+
return str;
1459+
}
1460+
var sepRegex = /[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;
1461+
if (typeof num === 'number') {
1462+
var int = num < 0 ? -$floor(-num) : $floor(num); // trunc(num)
1463+
if (int !== num) {
1464+
var intStr = String(int);
1465+
var dec = $slice.call(str, intStr.length + 1);
1466+
return $replace.call(intStr, sepRegex, '$&_') + '.' + $replace.call($replace.call(dec, /([0-9]{3})/g, '$&_'), /_$/, '');
1467+
}
1468+
}
1469+
return $replace.call(str, sepRegex, '$&_');
1470+
}
1471+
14371472
var inspectCustom = require('./util.inspect').custom;
14381473
var inspectSymbol = inspectCustom && isSymbol(inspectCustom) ? inspectCustom : null;
1439-
var toStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag !== 'undefined' ? Symbol.toStringTag : null;
14401474

14411475
module.exports = function inspect_(obj, options, depth, seen) {
14421476
var opts = options || {};
@@ -1463,8 +1497,12 @@ module.exports = function inspect_(obj, options, depth, seen) {
14631497
&& opts.indent !== '\t'
14641498
&& !(parseInt(opts.indent, 10) === opts.indent && opts.indent > 0)
14651499
) {
1466-
throw new TypeError('options "indent" must be "\\t", an integer > 0, or `null`');
1500+
throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');
14671501
}
1502+
if (has(opts, 'numericSeparator') && typeof opts.numericSeparator !== 'boolean') {
1503+
throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');
1504+
}
1505+
var numericSeparator = opts.numericSeparator;
14681506

14691507
if (typeof obj === 'undefined') {
14701508
return 'undefined';
@@ -1483,10 +1521,12 @@ module.exports = function inspect_(obj, options, depth, seen) {
14831521
if (obj === 0) {
14841522
return Infinity / obj > 0 ? '0' : '-0';
14851523
}
1486-
return String(obj);
1524+
var str = String(obj);
1525+
return numericSeparator ? addNumericSeparator(obj, str) : str;
14871526
}
14881527
if (typeof obj === 'bigint') {
1489-
return String(obj) + 'n';
1528+
var bigIntStr = String(obj) + 'n';
1529+
return numericSeparator ? addNumericSeparator(obj, bigIntStr) : bigIntStr;
14901530
}
14911531

14921532
var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
@@ -1505,7 +1545,7 @@ module.exports = function inspect_(obj, options, depth, seen) {
15051545

15061546
function inspect(value, from, noIndent) {
15071547
if (from) {
1508-
seen = seen.slice();
1548+
seen = $arrSlice.call(seen);
15091549
seen.push(from);
15101550
}
15111551
if (noIndent) {
@@ -1523,21 +1563,21 @@ module.exports = function inspect_(obj, options, depth, seen) {
15231563
if (typeof obj === 'function') {
15241564
var name = nameOf(obj);
15251565
var keys = arrObjKeys(obj, inspect);
1526-
return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + keys.join(', ') + ' }' : '');
1566+
return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + $join.call(keys, ', ') + ' }' : '');
15271567
}
15281568
if (isSymbol(obj)) {
1529-
var symString = hasShammedSymbols ? String(obj).replace(/^(Symbol\(.*\))_[^)]*$/, '$1') : symToString.call(obj);
1569+
var symString = hasShammedSymbols ? $replace.call(String(obj), /^(Symbol\(.*\))_[^)]*$/, '$1') : symToString.call(obj);
15301570
return typeof obj === 'object' && !hasShammedSymbols ? markBoxed(symString) : symString;
15311571
}
15321572
if (isElement(obj)) {
1533-
var s = '<' + String(obj.nodeName).toLowerCase();
1573+
var s = '<' + $toLowerCase.call(String(obj.nodeName));
15341574
var attrs = obj.attributes || [];
15351575
for (var i = 0; i < attrs.length; i++) {
15361576
s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts);
15371577
}
15381578
s += '>';
15391579
if (obj.childNodes && obj.childNodes.length) { s += '...'; }
1540-
s += '</' + String(obj.nodeName).toLowerCase() + '>';
1580+
s += '</' + $toLowerCase.call(String(obj.nodeName)) + '>';
15411581
return s;
15421582
}
15431583
if (isArray(obj)) {
@@ -1546,12 +1586,15 @@ module.exports = function inspect_(obj, options, depth, seen) {
15461586
if (indent && !singleLineValues(xs)) {
15471587
return '[' + indentedJoin(xs, indent) + ']';
15481588
}
1549-
return '[ ' + xs.join(', ') + ' ]';
1589+
return '[ ' + $join.call(xs, ', ') + ' ]';
15501590
}
15511591
if (isError(obj)) {
15521592
var parts = arrObjKeys(obj, inspect);
1593+
if ('cause' in obj && !isEnumerable.call(obj, 'cause')) {
1594+
return '{ [' + String(obj) + '] ' + $join.call($concat.call('[cause]: ' + inspect(obj.cause), parts), ', ') + ' }';
1595+
}
15531596
if (parts.length === 0) { return '[' + String(obj) + ']'; }
1554-
return '{ [' + String(obj) + '] ' + parts.join(', ') + ' }';
1597+
return '{ [' + String(obj) + '] ' + $join.call(parts, ', ') + ' }';
15551598
}
15561599
if (typeof obj === 'object' && customInspect) {
15571600
if (inspectSymbol && typeof obj[inspectSymbol] === 'function') {
@@ -1599,14 +1642,14 @@ module.exports = function inspect_(obj, options, depth, seen) {
15991642
var ys = arrObjKeys(obj, inspect);
16001643
var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object;
16011644
var protoTag = obj instanceof Object ? '' : 'null prototype';
1602-
var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? toStr(obj).slice(8, -1) : protoTag ? 'Object' : '';
1645+
var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? $slice.call(toStr(obj), 8, -1) : protoTag ? 'Object' : '';
16031646
var constructorTag = isPlainObject || typeof obj.constructor !== 'function' ? '' : obj.constructor.name ? obj.constructor.name + ' ' : '';
1604-
var tag = constructorTag + (stringTag || protoTag ? '[' + [].concat(stringTag || [], protoTag || []).join(': ') + '] ' : '');
1647+
var tag = constructorTag + (stringTag || protoTag ? '[' + $join.call($concat.call([], stringTag || [], protoTag || []), ': ') + '] ' : '');
16051648
if (ys.length === 0) { return tag + '{}'; }
16061649
if (indent) {
16071650
return tag + '{' + indentedJoin(ys, indent) + '}';
16081651
}
1609-
return tag + '{ ' + ys.join(', ') + ' }';
1652+
return tag + '{ ' + $join.call(ys, ', ') + ' }';
16101653
}
16111654
return String(obj);
16121655
};
@@ -1617,7 +1660,7 @@ function wrapQuotes(s, defaultStyle, opts) {
16171660
}
16181661

16191662
function quote(s) {
1620-
return String(s).replace(/"/g, '&quot;');
1663+
return $replace.call(String(s), /"/g, '&quot;');
16211664
}
16221665

16231666
function isArray(obj) { return toStr(obj) === '[object Array]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); }
@@ -1668,7 +1711,7 @@ function toStr(obj) {
16681711

16691712
function nameOf(f) {
16701713
if (f.name) { return f.name; }
1671-
var m = match.call(functionToString.call(f), /^function\s*([\w$]+)/);
1714+
var m = $match.call(functionToString.call(f), /^function\s*([\w$]+)/);
16721715
if (m) { return m[1]; }
16731716
return null;
16741717
}
@@ -1768,10 +1811,10 @@ function inspectString(str, opts) {
17681811
if (str.length > opts.maxStringLength) {
17691812
var remaining = str.length - opts.maxStringLength;
17701813
var trailer = '... ' + remaining + ' more character' + (remaining > 1 ? 's' : '');
1771-
return inspectString(str.slice(0, opts.maxStringLength), opts) + trailer;
1814+
return inspectString($slice.call(str, 0, opts.maxStringLength), opts) + trailer;
17721815
}
17731816
// eslint-disable-next-line no-control-regex
1774-
var s = str.replace(/(['\\])/g, '\\$1').replace(/[\x00-\x1f]/g, lowbyte);
1817+
var s = $replace.call($replace.call(str, /(['\\])/g, '\\$1'), /[\x00-\x1f]/g, lowbyte);
17751818
return wrapQuotes(s, 'single', opts);
17761819
}
17771820

@@ -1785,7 +1828,7 @@ function lowbyte(c) {
17851828
13: 'r'
17861829
}[n];
17871830
if (x) { return '\\' + x; }
1788-
return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16).toUpperCase();
1831+
return '\\x' + (n < 0x10 ? '0' : '') + $toUpperCase.call(n.toString(16));
17891832
}
17901833

17911834
function markBoxed(str) {
@@ -1797,7 +1840,7 @@ function weakCollectionOf(type) {
17971840
}
17981841

17991842
function collectionOf(type, size, entries, indent) {
1800-
var joinedEntries = indent ? indentedJoin(entries, indent) : entries.join(', ');
1843+
var joinedEntries = indent ? indentedJoin(entries, indent) : $join.call(entries, ', ');
18011844
return type + ' (' + size + ') {' + joinedEntries + '}';
18021845
}
18031846

@@ -1815,20 +1858,20 @@ function getIndent(opts, depth) {
18151858
if (opts.indent === '\t') {
18161859
baseIndent = '\t';
18171860
} else if (typeof opts.indent === 'number' && opts.indent > 0) {
1818-
baseIndent = Array(opts.indent + 1).join(' ');
1861+
baseIndent = $join.call(Array(opts.indent + 1), ' ');
18191862
} else {
18201863
return null;
18211864
}
18221865
return {
18231866
base: baseIndent,
1824-
prev: Array(depth + 1).join(baseIndent)
1867+
prev: $join.call(Array(depth + 1), baseIndent)
18251868
};
18261869
}
18271870

18281871
function indentedJoin(xs, indent) {
18291872
if (xs.length === 0) { return ''; }
18301873
var lineJoiner = '\n' + indent.prev + indent.base;
1831-
return lineJoiner + xs.join(',' + lineJoiner) + '\n' + indent.prev;
1874+
return lineJoiner + $join.call(xs, ',' + lineJoiner) + '\n' + indent.prev;
18321875
}
18331876

18341877
function arrObjKeys(obj, inspect) {
@@ -1855,7 +1898,7 @@ function arrObjKeys(obj, inspect) {
18551898
if (hasShammedSymbols && symMap['$' + key] instanceof Symbol) {
18561899
// this is to prevent shammed Symbols, which are stored as strings, from being included in the string key section
18571900
continue; // eslint-disable-line no-restricted-syntax, no-continue
1858-
} else if ((/[^\w$]/).test(key)) {
1901+
} else if ($test.call(/[^\w$]/, key)) {
18591902
xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj));
18601903
} else {
18611904
xs.push(key + ': ' + inspect(obj[key], obj));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "qs",
33
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
44
"homepage": "https://github.com/ljharb/qs",
5-
"version": "6.10.2",
5+
"version": "6.10.3",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/ljharb/qs.git"

0 commit comments

Comments
 (0)