qs 6.3.0 → 6.3.1
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/.eslintrc +3 -3
- package/CHANGELOG.md +12 -0
- package/README.md +34 -1
- package/dist/qs.js +32 -19
- package/lib/parse.js +9 -9
- package/lib/stringify.js +22 -9
- package/lib/utils.js +1 -1
- package/package.json +7 -7
- package/test/.eslintrc +1 -0
- package/test/parse.js +29 -4
- package/test/stringify.js +1 -1
- package/CONTRIBUTING.md +0 -1
package/.eslintrc
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
"rules": {
|
|
7
7
|
"complexity": [2, 25],
|
|
8
|
-
"consistent-return":
|
|
8
|
+
"consistent-return": 1,
|
|
9
9
|
"id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
|
|
10
10
|
"indent": [2, 4],
|
|
11
11
|
"max-params": [2, 11],
|
|
12
12
|
"max-statements": [2, 42],
|
|
13
|
-
"no-extra-parens":
|
|
14
|
-
"no-continue":
|
|
13
|
+
"no-extra-parens": 1,
|
|
14
|
+
"no-continue": 1,
|
|
15
15
|
"no-magic-numbers": 0,
|
|
16
16
|
"no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
|
|
17
17
|
"operator-linebreak": 1
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## **6.3.1**
|
|
2
|
+
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties (thanks, @snyk!)
|
|
3
|
+
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `browserify`, `iconv-lite`, `qs-iconv`, `tape`
|
|
4
|
+
- [Tests] on all node minors; improve test matrix
|
|
5
|
+
- [Docs] document stringify option `allowDots` (#195)
|
|
6
|
+
- [Docs] add empty object and array values example (#195)
|
|
7
|
+
- [Docs] Fix minor inconsistency/typo (#192)
|
|
8
|
+
- [Docs] document stringify option `sort` (#191)
|
|
9
|
+
- [Refactor] `stringify`: throw faster with an invalid encoder
|
|
10
|
+
- [Refactor] remove unnecessary escapes (#184)
|
|
11
|
+
- Remove contributing.md, since `qs` is no longer part of `hapi` (#183)
|
|
12
|
+
|
|
1
13
|
## **6.3.0**
|
|
2
14
|
- [New] Add support for RFC 1738 (#174, #173)
|
|
3
15
|
- [New] `stringify`: Add `serializeDate` option to customize Date serialization (#159)
|
package/README.md
CHANGED
|
@@ -261,7 +261,7 @@ qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false });
|
|
|
261
261
|
// 'a=b&a=c&a=d'
|
|
262
262
|
```
|
|
263
263
|
|
|
264
|
-
You may use the `arrayFormat` option to specify the format of the output array
|
|
264
|
+
You may use the `arrayFormat` option to specify the format of the output array:
|
|
265
265
|
|
|
266
266
|
```javascript
|
|
267
267
|
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
|
|
@@ -272,12 +272,36 @@ qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
|
|
|
272
272
|
// 'a=b&a=c'
|
|
273
273
|
```
|
|
274
274
|
|
|
275
|
+
When objects are stringified, by default they use bracket notation:
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
qs.stringify({ a: { b: { c: 'd', e: 'f' } } });
|
|
279
|
+
// 'a[b][c]=d&a[b][e]=f'
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
You may override this to use dot notation by setting the `allowDots` option to `true`:
|
|
283
|
+
|
|
284
|
+
```javascript
|
|
285
|
+
qs.stringify({ a: { b: { c: 'd', e: 'f' } } }, { allowDots: true });
|
|
286
|
+
// 'a.b.c=d&a.b.e=f'
|
|
287
|
+
```
|
|
288
|
+
|
|
275
289
|
Empty strings and null values will omit the value, but the equals sign (=) remains in place:
|
|
276
290
|
|
|
277
291
|
```javascript
|
|
278
292
|
assert.equal(qs.stringify({ a: '' }), 'a=');
|
|
279
293
|
```
|
|
280
294
|
|
|
295
|
+
Key with no values (such as an empty object or array) will return nothing:
|
|
296
|
+
|
|
297
|
+
```javascript
|
|
298
|
+
assert.equal(qs.stringify({ a: [] }), '');
|
|
299
|
+
assert.equal(qs.stringify({ a: {} }), '');
|
|
300
|
+
assert.equal(qs.stringify({ a: [{}] }), '');
|
|
301
|
+
assert.equal(qs.stringify({ a: { b: []} }), '');
|
|
302
|
+
assert.equal(qs.stringify({ a: { b: {}} }), '');
|
|
303
|
+
```
|
|
304
|
+
|
|
281
305
|
Properties that are set to `undefined` will be omitted entirely:
|
|
282
306
|
|
|
283
307
|
```javascript
|
|
@@ -301,6 +325,15 @@ assert.equal(
|
|
|
301
325
|
);
|
|
302
326
|
```
|
|
303
327
|
|
|
328
|
+
You may use the `sort` option to affect the order of parameter keys:
|
|
329
|
+
|
|
330
|
+
```javascript
|
|
331
|
+
function alphabeticalSort(a, b) {
|
|
332
|
+
return a.localeCompare(b);
|
|
333
|
+
}
|
|
334
|
+
assert.equal(qs.stringify({ a: 'c', z: 'y', b : 'f' }, { sort: alphabeticalSort }), 'a=c&b=f&z=y');
|
|
335
|
+
```
|
|
336
|
+
|
|
304
337
|
Finally, you can use the `filter` option to restrict which keys will be included in the stringified output.
|
|
305
338
|
If you pass a function, it will be called for each key to obtain the replacement value. Otherwise, if you
|
|
306
339
|
pass an array, it will be used to select properties and array indices for stringification:
|
package/dist/qs.js
CHANGED
|
@@ -50,7 +50,7 @@ var defaults = {
|
|
|
50
50
|
strictNullHandling: false
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
var parseValues = function
|
|
53
|
+
var parseValues = function parseQueryStringValues(str, options) {
|
|
54
54
|
var obj = {};
|
|
55
55
|
var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
|
|
56
56
|
|
|
@@ -76,7 +76,7 @@ var parseValues = function parseValues(str, options) {
|
|
|
76
76
|
return obj;
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
-
var parseObject = function
|
|
79
|
+
var parseObject = function parseObjectRecursive(chain, val, options) {
|
|
80
80
|
if (!chain.length) {
|
|
81
81
|
return val;
|
|
82
82
|
}
|
|
@@ -89,7 +89,7 @@ var parseObject = function parseObject(chain, val, options) {
|
|
|
89
89
|
obj = obj.concat(parseObject(chain, val, options));
|
|
90
90
|
} else {
|
|
91
91
|
obj = options.plainObjects ? Object.create(null) : {};
|
|
92
|
-
var cleanRoot = root
|
|
92
|
+
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
|
93
93
|
var index = parseInt(cleanRoot, 10);
|
|
94
94
|
if (
|
|
95
95
|
!isNaN(index) &&
|
|
@@ -108,18 +108,18 @@ var parseObject = function parseObject(chain, val, options) {
|
|
|
108
108
|
return obj;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
var parseKeys = function
|
|
111
|
+
var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
|
|
112
112
|
if (!givenKey) {
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
// Transform dot notation to bracket notation
|
|
117
|
-
var key = options.allowDots ? givenKey.replace(/\.([
|
|
117
|
+
var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
|
|
118
118
|
|
|
119
119
|
// The regex chunks
|
|
120
120
|
|
|
121
|
-
var parent = /^([
|
|
122
|
-
var child = /(\[[
|
|
121
|
+
var parent = /^([^[]*)/;
|
|
122
|
+
var child = /(\[[^[\]]*])/g;
|
|
123
123
|
|
|
124
124
|
// Get the parent
|
|
125
125
|
|
|
@@ -145,9 +145,9 @@ var parseKeys = function parseKeys(givenKey, val, options) {
|
|
|
145
145
|
var i = 0;
|
|
146
146
|
while ((segment = child.exec(key)) !== null && i < options.depth) {
|
|
147
147
|
i += 1;
|
|
148
|
-
if (!options.plainObjects && has.call(Object.prototype, segment[1].
|
|
148
|
+
if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
|
|
149
149
|
if (!options.allowPrototypes) {
|
|
150
|
-
|
|
150
|
+
return;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
keys.push(segment[1]);
|
|
@@ -206,13 +206,13 @@ var utils = require('./utils');
|
|
|
206
206
|
var formats = require('./formats');
|
|
207
207
|
|
|
208
208
|
var arrayPrefixGenerators = {
|
|
209
|
-
brackets: function brackets(prefix) {
|
|
209
|
+
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
|
|
210
210
|
return prefix + '[]';
|
|
211
211
|
},
|
|
212
|
-
indices: function indices(prefix, key) {
|
|
212
|
+
indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
|
|
213
213
|
return prefix + '[' + key + ']';
|
|
214
214
|
},
|
|
215
|
-
repeat: function repeat(prefix) {
|
|
215
|
+
repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
|
|
216
216
|
return prefix;
|
|
217
217
|
}
|
|
218
218
|
};
|
|
@@ -223,14 +223,26 @@ var defaults = {
|
|
|
223
223
|
delimiter: '&',
|
|
224
224
|
encode: true,
|
|
225
225
|
encoder: utils.encode,
|
|
226
|
-
serializeDate: function serializeDate(date) {
|
|
226
|
+
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
|
|
227
227
|
return toISO.call(date);
|
|
228
228
|
},
|
|
229
229
|
skipNulls: false,
|
|
230
230
|
strictNullHandling: false
|
|
231
231
|
};
|
|
232
232
|
|
|
233
|
-
var stringify = function stringify(
|
|
233
|
+
var stringify = function stringify( // eslint-disable-line func-name-matching
|
|
234
|
+
object,
|
|
235
|
+
prefix,
|
|
236
|
+
generateArrayPrefix,
|
|
237
|
+
strictNullHandling,
|
|
238
|
+
skipNulls,
|
|
239
|
+
encoder,
|
|
240
|
+
filter,
|
|
241
|
+
sort,
|
|
242
|
+
allowDots,
|
|
243
|
+
serializeDate,
|
|
244
|
+
formatter
|
|
245
|
+
) {
|
|
234
246
|
var obj = object;
|
|
235
247
|
if (typeof filter === 'function') {
|
|
236
248
|
obj = filter(prefix, obj);
|
|
@@ -309,6 +321,11 @@ var stringify = function stringify(object, prefix, generateArrayPrefix, strictNu
|
|
|
309
321
|
module.exports = function (object, opts) {
|
|
310
322
|
var obj = object;
|
|
311
323
|
var options = opts || {};
|
|
324
|
+
|
|
325
|
+
if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
|
|
326
|
+
throw new TypeError('Encoder has to be a function.');
|
|
327
|
+
}
|
|
328
|
+
|
|
312
329
|
var delimiter = typeof options.delimiter === 'undefined' ? defaults.delimiter : options.delimiter;
|
|
313
330
|
var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
|
|
314
331
|
var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls;
|
|
@@ -326,10 +343,6 @@ module.exports = function (object, opts) {
|
|
|
326
343
|
var objKeys;
|
|
327
344
|
var filter;
|
|
328
345
|
|
|
329
|
-
if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
|
|
330
|
-
throw new TypeError('Encoder has to be a function.');
|
|
331
|
-
}
|
|
332
|
-
|
|
333
346
|
if (typeof options.filter === 'function') {
|
|
334
347
|
filter = options.filter;
|
|
335
348
|
obj = filter('', obj);
|
|
@@ -517,7 +530,7 @@ exports.encode = function (str) {
|
|
|
517
530
|
|
|
518
531
|
i += 1;
|
|
519
532
|
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
|
|
520
|
-
out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)];
|
|
533
|
+
out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len
|
|
521
534
|
}
|
|
522
535
|
|
|
523
536
|
return out;
|
package/lib/parse.js
CHANGED
|
@@ -16,7 +16,7 @@ var defaults = {
|
|
|
16
16
|
strictNullHandling: false
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
var parseValues = function
|
|
19
|
+
var parseValues = function parseQueryStringValues(str, options) {
|
|
20
20
|
var obj = {};
|
|
21
21
|
var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
|
|
22
22
|
|
|
@@ -42,7 +42,7 @@ var parseValues = function parseValues(str, options) {
|
|
|
42
42
|
return obj;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
var parseObject = function
|
|
45
|
+
var parseObject = function parseObjectRecursive(chain, val, options) {
|
|
46
46
|
if (!chain.length) {
|
|
47
47
|
return val;
|
|
48
48
|
}
|
|
@@ -55,7 +55,7 @@ var parseObject = function parseObject(chain, val, options) {
|
|
|
55
55
|
obj = obj.concat(parseObject(chain, val, options));
|
|
56
56
|
} else {
|
|
57
57
|
obj = options.plainObjects ? Object.create(null) : {};
|
|
58
|
-
var cleanRoot = root
|
|
58
|
+
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
|
59
59
|
var index = parseInt(cleanRoot, 10);
|
|
60
60
|
if (
|
|
61
61
|
!isNaN(index) &&
|
|
@@ -74,18 +74,18 @@ var parseObject = function parseObject(chain, val, options) {
|
|
|
74
74
|
return obj;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
var parseKeys = function
|
|
77
|
+
var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
|
|
78
78
|
if (!givenKey) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// Transform dot notation to bracket notation
|
|
83
|
-
var key = options.allowDots ? givenKey.replace(/\.([
|
|
83
|
+
var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
|
|
84
84
|
|
|
85
85
|
// The regex chunks
|
|
86
86
|
|
|
87
|
-
var parent = /^([
|
|
88
|
-
var child = /(\[[
|
|
87
|
+
var parent = /^([^[]*)/;
|
|
88
|
+
var child = /(\[[^[\]]*])/g;
|
|
89
89
|
|
|
90
90
|
// Get the parent
|
|
91
91
|
|
|
@@ -111,9 +111,9 @@ var parseKeys = function parseKeys(givenKey, val, options) {
|
|
|
111
111
|
var i = 0;
|
|
112
112
|
while ((segment = child.exec(key)) !== null && i < options.depth) {
|
|
113
113
|
i += 1;
|
|
114
|
-
if (!options.plainObjects && has.call(Object.prototype, segment[1].
|
|
114
|
+
if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
|
|
115
115
|
if (!options.allowPrototypes) {
|
|
116
|
-
|
|
116
|
+
return;
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
keys.push(segment[1]);
|
package/lib/stringify.js
CHANGED
|
@@ -4,13 +4,13 @@ var utils = require('./utils');
|
|
|
4
4
|
var formats = require('./formats');
|
|
5
5
|
|
|
6
6
|
var arrayPrefixGenerators = {
|
|
7
|
-
brackets: function brackets(prefix) {
|
|
7
|
+
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
|
|
8
8
|
return prefix + '[]';
|
|
9
9
|
},
|
|
10
|
-
indices: function indices(prefix, key) {
|
|
10
|
+
indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
|
|
11
11
|
return prefix + '[' + key + ']';
|
|
12
12
|
},
|
|
13
|
-
repeat: function repeat(prefix) {
|
|
13
|
+
repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
|
|
14
14
|
return prefix;
|
|
15
15
|
}
|
|
16
16
|
};
|
|
@@ -21,14 +21,26 @@ var defaults = {
|
|
|
21
21
|
delimiter: '&',
|
|
22
22
|
encode: true,
|
|
23
23
|
encoder: utils.encode,
|
|
24
|
-
serializeDate: function serializeDate(date) {
|
|
24
|
+
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
|
|
25
25
|
return toISO.call(date);
|
|
26
26
|
},
|
|
27
27
|
skipNulls: false,
|
|
28
28
|
strictNullHandling: false
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
var stringify = function stringify(
|
|
31
|
+
var stringify = function stringify( // eslint-disable-line func-name-matching
|
|
32
|
+
object,
|
|
33
|
+
prefix,
|
|
34
|
+
generateArrayPrefix,
|
|
35
|
+
strictNullHandling,
|
|
36
|
+
skipNulls,
|
|
37
|
+
encoder,
|
|
38
|
+
filter,
|
|
39
|
+
sort,
|
|
40
|
+
allowDots,
|
|
41
|
+
serializeDate,
|
|
42
|
+
formatter
|
|
43
|
+
) {
|
|
32
44
|
var obj = object;
|
|
33
45
|
if (typeof filter === 'function') {
|
|
34
46
|
obj = filter(prefix, obj);
|
|
@@ -107,6 +119,11 @@ var stringify = function stringify(object, prefix, generateArrayPrefix, strictNu
|
|
|
107
119
|
module.exports = function (object, opts) {
|
|
108
120
|
var obj = object;
|
|
109
121
|
var options = opts || {};
|
|
122
|
+
|
|
123
|
+
if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
|
|
124
|
+
throw new TypeError('Encoder has to be a function.');
|
|
125
|
+
}
|
|
126
|
+
|
|
110
127
|
var delimiter = typeof options.delimiter === 'undefined' ? defaults.delimiter : options.delimiter;
|
|
111
128
|
var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
|
|
112
129
|
var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls;
|
|
@@ -124,10 +141,6 @@ module.exports = function (object, opts) {
|
|
|
124
141
|
var objKeys;
|
|
125
142
|
var filter;
|
|
126
143
|
|
|
127
|
-
if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
|
|
128
|
-
throw new TypeError('Encoder has to be a function.');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
144
|
if (typeof options.filter === 'function') {
|
|
132
145
|
filter = options.filter;
|
|
133
146
|
obj = filter('', obj);
|
package/lib/utils.js
CHANGED
|
@@ -126,7 +126,7 @@ exports.encode = function (str) {
|
|
|
126
126
|
|
|
127
127
|
i += 1;
|
|
128
128
|
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
|
|
129
|
-
out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)];
|
|
129
|
+
out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
return out;
|
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.3.
|
|
5
|
+
"version": "6.3.1",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/ljharb/qs.git"
|
|
@@ -24,17 +24,17 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@ljharb/eslint-config": "^
|
|
28
|
-
"browserify": "^
|
|
27
|
+
"@ljharb/eslint-config": "^11.0.0",
|
|
28
|
+
"browserify": "^14.1.0",
|
|
29
29
|
"covert": "^1.1.0",
|
|
30
|
-
"eslint": "^3.
|
|
30
|
+
"eslint": "^3.15.0",
|
|
31
31
|
"evalmd": "^0.0.17",
|
|
32
|
-
"iconv-lite": "^0.4.
|
|
32
|
+
"iconv-lite": "^0.4.15",
|
|
33
33
|
"mkdirp": "^0.5.1",
|
|
34
34
|
"parallelshell": "^2.0.0",
|
|
35
|
-
"qs-iconv": "^1.0.
|
|
35
|
+
"qs-iconv": "^1.0.4",
|
|
36
36
|
"safe-publish-latest": "^1.1.1",
|
|
37
|
-
"tape": "^4.6.
|
|
37
|
+
"tape": "^4.6.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"prepublish": "safe-publish-latest && npm run dist",
|
package/test/.eslintrc
CHANGED
package/test/parse.js
CHANGED
|
@@ -131,9 +131,9 @@ test('parse()', function (t) {
|
|
|
131
131
|
st.deepEqual(qs.parse('foo[bad]=baz&foo[]=bar&foo[]=foo'), { foo: { bad: 'baz', 0: 'bar', 1: 'foo' } });
|
|
132
132
|
st.deepEqual(qs.parse('foo[0][a]=a&foo[0][b]=b&foo[1][a]=aa&foo[1][b]=bb'), { foo: [{ a: 'a', b: 'b' }, { a: 'aa', b: 'bb' }] });
|
|
133
133
|
|
|
134
|
-
st.deepEqual(qs.parse('a[]=b&a[t]=u&a[hasOwnProperty]=c', { allowPrototypes: false }), { a: { 0: 'b',
|
|
134
|
+
st.deepEqual(qs.parse('a[]=b&a[t]=u&a[hasOwnProperty]=c', { allowPrototypes: false }), { a: { 0: 'b', t: 'u' } });
|
|
135
135
|
st.deepEqual(qs.parse('a[]=b&a[t]=u&a[hasOwnProperty]=c', { allowPrototypes: true }), { a: { 0: 'b', t: 'u', hasOwnProperty: 'c' } });
|
|
136
|
-
st.deepEqual(qs.parse('a[]=b&a[hasOwnProperty]=c&a[x]=y', { allowPrototypes: false }), { a: { 0: 'b',
|
|
136
|
+
st.deepEqual(qs.parse('a[]=b&a[hasOwnProperty]=c&a[x]=y', { allowPrototypes: false }), { a: { 0: 'b', x: 'y' } });
|
|
137
137
|
st.deepEqual(qs.parse('a[]=b&a[hasOwnProperty]=c&a[x]=y', { allowPrototypes: true }), { a: { 0: 'b', hasOwnProperty: 'c', x: 'y' } });
|
|
138
138
|
st.end();
|
|
139
139
|
});
|
|
@@ -413,9 +413,34 @@ test('parse()', function (t) {
|
|
|
413
413
|
st.end();
|
|
414
414
|
});
|
|
415
415
|
|
|
416
|
+
t.test('does not allow overwriting prototype properties', function (st) {
|
|
417
|
+
st.deepEqual(qs.parse('a[hasOwnProperty]=b', { allowPrototypes: false }), {});
|
|
418
|
+
st.deepEqual(qs.parse('hasOwnProperty=b', { allowPrototypes: false }), {});
|
|
419
|
+
|
|
420
|
+
st.deepEqual(
|
|
421
|
+
qs.parse('toString', { allowPrototypes: false }),
|
|
422
|
+
{},
|
|
423
|
+
'bare "toString" results in {}'
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
st.end();
|
|
427
|
+
});
|
|
428
|
+
|
|
416
429
|
t.test('can allow overwriting prototype properties', function (st) {
|
|
417
|
-
st.deepEqual(qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true }), { a: { hasOwnProperty: 'b' } }
|
|
418
|
-
st.deepEqual(qs.parse('hasOwnProperty=b', { allowPrototypes: true }), { hasOwnProperty: 'b' }
|
|
430
|
+
st.deepEqual(qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true }), { a: { hasOwnProperty: 'b' } });
|
|
431
|
+
st.deepEqual(qs.parse('hasOwnProperty=b', { allowPrototypes: true }), { hasOwnProperty: 'b' });
|
|
432
|
+
|
|
433
|
+
st.deepEqual(
|
|
434
|
+
qs.parse('toString', { allowPrototypes: true }),
|
|
435
|
+
{ toString: '' },
|
|
436
|
+
'bare "toString" results in { toString: "" }'
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
st.end();
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
t.test('params starting with a closing bracket', function (st) {
|
|
443
|
+
st.deepEqual(qs.parse(']=toString'), { ']': 'toString' });
|
|
419
444
|
st.end();
|
|
420
445
|
});
|
|
421
446
|
|
package/test/stringify.js
CHANGED
|
@@ -385,7 +385,7 @@ test('stringify()', function (t) {
|
|
|
385
385
|
st.equal(prefix, '', 'prefix is empty');
|
|
386
386
|
st.equal(value, obj);
|
|
387
387
|
} else if (prefix === 'c') {
|
|
388
|
-
return;
|
|
388
|
+
return void 0;
|
|
389
389
|
} else if (value instanceof Date) {
|
|
390
390
|
st.equal(prefix, 'e[f]');
|
|
391
391
|
return value.getTime();
|
package/CONTRIBUTING.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Please view our [hapijs contributing guide](https://github.com/hapijs/hapi/blob/master/CONTRIBUTING.md).
|