qs 6.2.2 → 6.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/qs.js +12 -7
- package/lib/index.js +0 -0
- package/lib/parse.js +6 -5
- package/lib/stringify.js +0 -0
- package/lib/utils.js +6 -2
- package/package.json +1 -1
- package/test/parse.js +38 -3
- package/test/stringify.js +0 -0
- package/test/utils.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## **6.2.3**
|
|
2
|
+
- [Fix] follow `allowPrototypes` option during merge (#201, #200)
|
|
3
|
+
- [Fix] chmod a-x
|
|
4
|
+
- [Fix] support keys starting with brackets (#202, #200)
|
|
5
|
+
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
|
|
6
|
+
|
|
1
7
|
## **6.2.2**
|
|
2
8
|
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
|
|
3
9
|
|
package/dist/qs.js
CHANGED
|
@@ -96,26 +96,27 @@ var parseKeys = function parseKeys(givenKey, val, options) {
|
|
|
96
96
|
|
|
97
97
|
// The regex chunks
|
|
98
98
|
|
|
99
|
-
var
|
|
99
|
+
var brackets = /(\[[^[\]]*])/;
|
|
100
100
|
var child = /(\[[^[\]]*])/g;
|
|
101
101
|
|
|
102
102
|
// Get the parent
|
|
103
103
|
|
|
104
|
-
var segment =
|
|
104
|
+
var segment = brackets.exec(key);
|
|
105
|
+
var parent = segment ? key.slice(0, segment.index) : key;
|
|
105
106
|
|
|
106
107
|
// Stash the parent if it exists
|
|
107
108
|
|
|
108
109
|
var keys = [];
|
|
109
|
-
if (
|
|
110
|
+
if (parent) {
|
|
110
111
|
// If we aren't using plain objects, optionally prefix keys
|
|
111
112
|
// that would overwrite object prototype properties
|
|
112
|
-
if (!options.plainObjects && has.call(Object.prototype,
|
|
113
|
+
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
|
113
114
|
if (!options.allowPrototypes) {
|
|
114
115
|
return;
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
keys.push(
|
|
119
|
+
keys.push(parent);
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
// Loop through children appending to the array until we hit depth
|
|
@@ -328,6 +329,8 @@ var hexTable = (function () {
|
|
|
328
329
|
return array;
|
|
329
330
|
}());
|
|
330
331
|
|
|
332
|
+
var has = Object.prototype.hasOwnProperty;
|
|
333
|
+
|
|
331
334
|
exports.arrayToObject = function (source, options) {
|
|
332
335
|
var obj = options.plainObjects ? Object.create(null) : {};
|
|
333
336
|
for (var i = 0; i < source.length; ++i) {
|
|
@@ -348,7 +351,9 @@ exports.merge = function (target, source, options) {
|
|
|
348
351
|
if (Array.isArray(target)) {
|
|
349
352
|
target.push(source);
|
|
350
353
|
} else if (typeof target === 'object') {
|
|
351
|
-
|
|
354
|
+
if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
|
|
355
|
+
target[source] = true;
|
|
356
|
+
}
|
|
352
357
|
} else {
|
|
353
358
|
return [target, source];
|
|
354
359
|
}
|
|
@@ -368,7 +373,7 @@ exports.merge = function (target, source, options) {
|
|
|
368
373
|
return Object.keys(source).reduce(function (acc, key) {
|
|
369
374
|
var value = source[key];
|
|
370
375
|
|
|
371
|
-
if (
|
|
376
|
+
if (has.call(acc, key)) {
|
|
372
377
|
acc[key] = exports.merge(acc[key], value, options);
|
|
373
378
|
} else {
|
|
374
379
|
acc[key] = value;
|
package/lib/index.js
CHANGED
|
File without changes
|
package/lib/parse.js
CHANGED
|
@@ -84,26 +84,27 @@ var parseKeys = function parseKeys(givenKey, val, options) {
|
|
|
84
84
|
|
|
85
85
|
// The regex chunks
|
|
86
86
|
|
|
87
|
-
var
|
|
87
|
+
var brackets = /(\[[^[\]]*])/;
|
|
88
88
|
var child = /(\[[^[\]]*])/g;
|
|
89
89
|
|
|
90
90
|
// Get the parent
|
|
91
91
|
|
|
92
|
-
var segment =
|
|
92
|
+
var segment = brackets.exec(key);
|
|
93
|
+
var parent = segment ? key.slice(0, segment.index) : key;
|
|
93
94
|
|
|
94
95
|
// Stash the parent if it exists
|
|
95
96
|
|
|
96
97
|
var keys = [];
|
|
97
|
-
if (
|
|
98
|
+
if (parent) {
|
|
98
99
|
// If we aren't using plain objects, optionally prefix keys
|
|
99
100
|
// that would overwrite object prototype properties
|
|
100
|
-
if (!options.plainObjects && has.call(Object.prototype,
|
|
101
|
+
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
|
101
102
|
if (!options.allowPrototypes) {
|
|
102
103
|
return;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
keys.push(
|
|
107
|
+
keys.push(parent);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
// Loop through children appending to the array until we hit depth
|
package/lib/stringify.js
CHANGED
|
File without changes
|
package/lib/utils.js
CHANGED
|
@@ -9,6 +9,8 @@ var hexTable = (function () {
|
|
|
9
9
|
return array;
|
|
10
10
|
}());
|
|
11
11
|
|
|
12
|
+
var has = Object.prototype.hasOwnProperty;
|
|
13
|
+
|
|
12
14
|
exports.arrayToObject = function (source, options) {
|
|
13
15
|
var obj = options.plainObjects ? Object.create(null) : {};
|
|
14
16
|
for (var i = 0; i < source.length; ++i) {
|
|
@@ -29,7 +31,9 @@ exports.merge = function (target, source, options) {
|
|
|
29
31
|
if (Array.isArray(target)) {
|
|
30
32
|
target.push(source);
|
|
31
33
|
} else if (typeof target === 'object') {
|
|
32
|
-
|
|
34
|
+
if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
|
|
35
|
+
target[source] = true;
|
|
36
|
+
}
|
|
33
37
|
} else {
|
|
34
38
|
return [target, source];
|
|
35
39
|
}
|
|
@@ -49,7 +53,7 @@ exports.merge = function (target, source, options) {
|
|
|
49
53
|
return Object.keys(source).reduce(function (acc, key) {
|
|
50
54
|
var value = source[key];
|
|
51
55
|
|
|
52
|
-
if (
|
|
56
|
+
if (has.call(acc, key)) {
|
|
53
57
|
acc[key] = exports.merge(acc[key], value, options);
|
|
54
58
|
} else {
|
|
55
59
|
acc[key] = value;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "qs",
|
|
3
3
|
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
|
|
4
4
|
"homepage": "https://github.com/ljharb/qs",
|
|
5
|
-
"version": "6.2.
|
|
5
|
+
"version": "6.2.3",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/ljharb/qs.git"
|
package/test/parse.js
CHANGED
|
@@ -143,8 +143,6 @@ test('parse()', function (t) {
|
|
|
143
143
|
st.end();
|
|
144
144
|
});
|
|
145
145
|
|
|
146
|
-
t.deepEqual(qs.parse('a[b]=c&a=d'), { a: { b: 'c', d: true } }, 'can add keys to objects');
|
|
147
|
-
|
|
148
146
|
t.test('correctly prunes undefined values when converting an array to an object', function (st) {
|
|
149
147
|
st.deepEqual(qs.parse('a[2]=b&a[99999999]=c'), { a: { '2': 'b', '99999999': 'c' } });
|
|
150
148
|
st.end();
|
|
@@ -430,10 +428,47 @@ test('parse()', function (t) {
|
|
|
430
428
|
|
|
431
429
|
t.test('params starting with a closing bracket', function (st) {
|
|
432
430
|
st.deepEqual(qs.parse(']=toString'), { ']': 'toString' });
|
|
431
|
+
st.deepEqual(qs.parse(']]=toString'), { ']]': 'toString' });
|
|
432
|
+
st.deepEqual(qs.parse(']hello]=toString'), { ']hello]': 'toString' });
|
|
433
|
+
st.end();
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
t.test('params starting with a starting bracket', function (st) {
|
|
437
|
+
st.deepEqual(qs.parse('[=toString'), { '[': 'toString' });
|
|
438
|
+
st.deepEqual(qs.parse('[[=toString'), { '[[': 'toString' });
|
|
439
|
+
st.deepEqual(qs.parse('[hello[=toString'), { '[hello[': 'toString' });
|
|
440
|
+
st.end();
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
t.test('add keys to objects', function (st) {
|
|
444
|
+
st.deepEqual(
|
|
445
|
+
qs.parse('a[b]=c&a=d'),
|
|
446
|
+
{ a: { b: 'c', d: true } },
|
|
447
|
+
'can add keys to objects'
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
st.deepEqual(
|
|
451
|
+
qs.parse('a[b]=c&a=toString'),
|
|
452
|
+
{ a: { b: 'c' } },
|
|
453
|
+
'can not overwrite prototype'
|
|
454
|
+
);
|
|
455
|
+
|
|
456
|
+
st.deepEqual(
|
|
457
|
+
qs.parse('a[b]=c&a=toString', { allowPrototypes: true }),
|
|
458
|
+
{ a: { b: 'c', toString: true } },
|
|
459
|
+
'can overwrite prototype with allowPrototypes true'
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
st.deepEqual(
|
|
463
|
+
qs.parse('a[b]=c&a=toString', { plainObjects: true }),
|
|
464
|
+
{ a: { b: 'c', toString: true } },
|
|
465
|
+
'can overwrite prototype with plainObjects true'
|
|
466
|
+
);
|
|
467
|
+
|
|
433
468
|
st.end();
|
|
434
469
|
});
|
|
435
470
|
|
|
436
|
-
t.test('can return
|
|
471
|
+
t.test('can return null objects', { skip: !Object.create }, function (st) {
|
|
437
472
|
var expected = Object.create(null);
|
|
438
473
|
expected.a = Object.create(null);
|
|
439
474
|
expected.a.b = 'c';
|
package/test/stringify.js
CHANGED
|
File without changes
|
package/test/utils.js
CHANGED
|
File without changes
|