qs 6.3.3 → 6.5.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/.editorconfig +1 -15
- package/.eslintignore +1 -0
- package/.eslintrc +4 -22
- package/CHANGELOG.md +57 -19
- package/LICENSE +28 -0
- package/README.md +82 -62
- package/dist/qs.js +129 -104
- package/lib/formats.js +1 -1
- package/lib/parse.js +40 -34
- package/lib/stringify.js +34 -31
- package/lib/utils.js +55 -39
- package/package.json +16 -19
- package/test/.eslintrc +15 -0
- package/test/parse.js +58 -72
- package/test/stringify.js +62 -34
- package/test/utils.js +11 -6
- package/.github/FUNDING.yml +0 -12
- package/.nycrc +0 -13
- package/LICENSE.md +0 -29
- package/bower.json +0 -21
- package/component.json +0 -15
package/test/stringify.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var test = require('tape');
|
|
4
4
|
var qs = require('../');
|
|
5
|
+
var utils = require('../lib/utils');
|
|
5
6
|
var iconv = require('iconv-lite');
|
|
6
|
-
var SaferBuffer = require('safer-buffer').Buffer;
|
|
7
7
|
|
|
8
8
|
test('stringify()', function (t) {
|
|
9
9
|
t.test('stringifies a querystring object', function (st) {
|
|
@@ -18,6 +18,16 @@ test('stringify()', function (t) {
|
|
|
18
18
|
st.end();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
+
t.test('adds query prefix', function (st) {
|
|
22
|
+
st.equal(qs.stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b');
|
|
23
|
+
st.end();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
t.test('with query prefix, outputs blank string given an empty object', function (st) {
|
|
27
|
+
st.equal(qs.stringify({}, { addQueryPrefix: true }), '');
|
|
28
|
+
st.end();
|
|
29
|
+
});
|
|
30
|
+
|
|
21
31
|
t.test('stringifies a nested object', function (st) {
|
|
22
32
|
st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
|
|
23
33
|
st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }), 'a%5Bb%5D%5Bc%5D%5Bd%5D=e');
|
|
@@ -326,8 +336,8 @@ test('stringify()', function (t) {
|
|
|
326
336
|
});
|
|
327
337
|
|
|
328
338
|
t.test('stringifies buffer values', function (st) {
|
|
329
|
-
st.equal(qs.stringify({ a:
|
|
330
|
-
st.equal(qs.stringify({ a: { b:
|
|
339
|
+
st.equal(qs.stringify({ a: new Buffer('test') }), 'a=test');
|
|
340
|
+
st.equal(qs.stringify({ a: { b: new Buffer('test') } }), 'a%5Bb%5D=test');
|
|
331
341
|
st.end();
|
|
332
342
|
});
|
|
333
343
|
|
|
@@ -453,6 +463,16 @@ test('stringify()', function (t) {
|
|
|
453
463
|
st.end();
|
|
454
464
|
});
|
|
455
465
|
|
|
466
|
+
t.test('receives the default encoder as a second argument', function (st) {
|
|
467
|
+
st.plan(2);
|
|
468
|
+
qs.stringify({ a: 1 }, {
|
|
469
|
+
encoder: function (str, defaultEncoder) {
|
|
470
|
+
st.equal(defaultEncoder, utils.encode);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
st.end();
|
|
474
|
+
});
|
|
475
|
+
|
|
456
476
|
t.test('throws error with wrong encoder', function (st) {
|
|
457
477
|
st['throws'](function () {
|
|
458
478
|
qs.stringify({}, { encoder: 'string' });
|
|
@@ -461,7 +481,7 @@ test('stringify()', function (t) {
|
|
|
461
481
|
});
|
|
462
482
|
|
|
463
483
|
t.test('can use custom encoder for a buffer object', { skip: typeof Buffer === 'undefined' }, function (st) {
|
|
464
|
-
st.equal(qs.stringify({ a:
|
|
484
|
+
st.equal(qs.stringify({ a: new Buffer([1]) }, {
|
|
465
485
|
encoder: function (buffer) {
|
|
466
486
|
if (typeof buffer === 'string') {
|
|
467
487
|
return buffer;
|
|
@@ -469,12 +489,6 @@ test('stringify()', function (t) {
|
|
|
469
489
|
return String.fromCharCode(buffer.readUInt8(0) + 97);
|
|
470
490
|
}
|
|
471
491
|
}), 'a=b');
|
|
472
|
-
|
|
473
|
-
st.equal(qs.stringify({ a: SaferBuffer.from('a b') }, {
|
|
474
|
-
encoder: function (buffer) {
|
|
475
|
-
return buffer;
|
|
476
|
-
}
|
|
477
|
-
}), 'a=a b');
|
|
478
492
|
st.end();
|
|
479
493
|
});
|
|
480
494
|
|
|
@@ -515,52 +529,66 @@ test('stringify()', function (t) {
|
|
|
515
529
|
t.test('RFC 1738 spaces serialization', function (st) {
|
|
516
530
|
st.equal(qs.stringify({ a: 'b c' }, { format: qs.formats.RFC1738 }), 'a=b+c');
|
|
517
531
|
st.equal(qs.stringify({ 'a b': 'c d' }, { format: qs.formats.RFC1738 }), 'a+b=c+d');
|
|
518
|
-
st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }, { format: qs.formats.RFC1738 }), 'a+b=a+b');
|
|
519
532
|
st.end();
|
|
520
533
|
});
|
|
521
534
|
|
|
522
535
|
t.test('RFC 3986 spaces serialization', function (st) {
|
|
523
536
|
st.equal(qs.stringify({ a: 'b c' }, { format: qs.formats.RFC3986 }), 'a=b%20c');
|
|
524
537
|
st.equal(qs.stringify({ 'a b': 'c d' }, { format: qs.formats.RFC3986 }), 'a%20b=c%20d');
|
|
525
|
-
st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }, { format: qs.formats.RFC3986 }), 'a%20b=a%20b');
|
|
526
538
|
st.end();
|
|
527
539
|
});
|
|
528
540
|
|
|
529
541
|
t.test('Backward compatibility to RFC 3986', function (st) {
|
|
530
542
|
st.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
|
|
531
|
-
st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }), 'a%20b=a%20b');
|
|
532
543
|
st.end();
|
|
533
544
|
});
|
|
534
545
|
|
|
535
546
|
t.test('Edge cases and unknown formats', function (st) {
|
|
536
|
-
['UFO1234', false, 1234, null, {}, []].forEach(
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
547
|
+
['UFO1234', false, 1234, null, {}, []].forEach(
|
|
548
|
+
function (format) {
|
|
549
|
+
st['throws'](
|
|
550
|
+
function () {
|
|
551
|
+
qs.stringify({ a: 'b c' }, { format: format });
|
|
552
|
+
},
|
|
553
|
+
new TypeError('Unknown format option provided.')
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
);
|
|
544
557
|
st.end();
|
|
545
558
|
});
|
|
546
559
|
|
|
547
|
-
t.test('
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
560
|
+
t.test('encodeValuesOnly', function (st) {
|
|
561
|
+
st.equal(
|
|
562
|
+
qs.stringify(
|
|
563
|
+
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
|
564
|
+
{ encodeValuesOnly: true }
|
|
565
|
+
),
|
|
566
|
+
'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h'
|
|
567
|
+
);
|
|
568
|
+
st.equal(
|
|
569
|
+
qs.stringify(
|
|
570
|
+
{ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }
|
|
571
|
+
),
|
|
572
|
+
'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h'
|
|
573
|
+
);
|
|
574
|
+
st.end();
|
|
575
|
+
});
|
|
551
576
|
|
|
552
|
-
|
|
553
|
-
st.equal(
|
|
577
|
+
t.test('encodeValuesOnly - strictNullHandling', function (st) {
|
|
578
|
+
st.equal(
|
|
579
|
+
qs.stringify(
|
|
580
|
+
{ a: { b: null } },
|
|
581
|
+
{ encodeValuesOnly: true, strictNullHandling: true }
|
|
582
|
+
),
|
|
583
|
+
'a[b]'
|
|
584
|
+
);
|
|
554
585
|
st.end();
|
|
555
586
|
});
|
|
556
587
|
|
|
557
|
-
t.test('
|
|
558
|
-
var
|
|
559
|
-
|
|
560
|
-
};
|
|
561
|
-
var options = { strictNullHandling: true, serializeDate: serializeDate };
|
|
562
|
-
var date = new Date();
|
|
563
|
-
st.equal(qs.stringify({ key: date }, options), 'key');
|
|
588
|
+
t.test('does not mutate the options argument', function (st) {
|
|
589
|
+
var options = {};
|
|
590
|
+
qs.stringify({}, options);
|
|
591
|
+
st.deepEqual(options, {});
|
|
564
592
|
st.end();
|
|
565
593
|
});
|
|
566
594
|
|
package/test/utils.js
CHANGED
|
@@ -4,10 +4,6 @@ var test = require('tape');
|
|
|
4
4
|
var utils = require('../lib/utils');
|
|
5
5
|
|
|
6
6
|
test('merge()', function (t) {
|
|
7
|
-
t.deepEqual(utils.merge(null, true), [null, true], 'merges true into null');
|
|
8
|
-
|
|
9
|
-
t.deepEqual(utils.merge(null, [42]), [null, 42], 'merges null into an array');
|
|
10
|
-
|
|
11
7
|
t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key');
|
|
12
8
|
|
|
13
9
|
var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });
|
|
@@ -22,8 +18,17 @@ test('merge()', function (t) {
|
|
|
22
18
|
var nestedArrays = utils.merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] });
|
|
23
19
|
t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] });
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
t.end();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('assign()', function (t) {
|
|
25
|
+
var target = { a: 1, b: 2 };
|
|
26
|
+
var source = { b: 3, c: 4 };
|
|
27
|
+
var result = utils.assign(target, source);
|
|
28
|
+
|
|
29
|
+
t.equal(result, target, 'returns the target');
|
|
30
|
+
t.deepEqual(target, { a: 1, b: 3, c: 4 }, 'target and source are merged');
|
|
31
|
+
t.deepEqual(source, { b: 3, c: 4 }, 'source is untouched');
|
|
27
32
|
|
|
28
33
|
t.end();
|
|
29
34
|
});
|
package/.github/FUNDING.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# These are supported funding model platforms
|
|
2
|
-
|
|
3
|
-
github: [ljharb]
|
|
4
|
-
patreon: # Replace with a single Patreon username
|
|
5
|
-
open_collective: # Replace with a single Open Collective username
|
|
6
|
-
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
-
tidelift: npm/qs
|
|
8
|
-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
-
liberapay: # Replace with a single Liberapay username
|
|
10
|
-
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
-
otechie: # Replace with a single Otechie username
|
|
12
|
-
custom: # Replace with a single custom sponsorship URL
|
package/.nycrc
DELETED
package/LICENSE.md
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
BSD 3-Clause License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014, Nathan LaFreniere and other [contributors](https://github.com/ljharb/qs/graphs/contributors)
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
|
7
|
-
modification, are permitted provided that the following conditions are met:
|
|
8
|
-
|
|
9
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
-
list of conditions and the following disclaimer.
|
|
11
|
-
|
|
12
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
-
this list of conditions and the following disclaimer in the documentation
|
|
14
|
-
and/or other materials provided with the distribution.
|
|
15
|
-
|
|
16
|
-
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
-
contributors may be used to endorse or promote products derived from
|
|
18
|
-
this software without specific prior written permission.
|
|
19
|
-
|
|
20
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/bower.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "qs",
|
|
3
|
-
"main": "dist/qs.js",
|
|
4
|
-
"homepage": "https://github.com/hapijs/qs",
|
|
5
|
-
"authors": [
|
|
6
|
-
"Nathan LaFreniere <quitlahok@gmail.com>"
|
|
7
|
-
],
|
|
8
|
-
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
|
|
9
|
-
"keywords": [
|
|
10
|
-
"querystring",
|
|
11
|
-
"qs"
|
|
12
|
-
],
|
|
13
|
-
"license": "BSD-3-Clause",
|
|
14
|
-
"ignore": [
|
|
15
|
-
"**/.*",
|
|
16
|
-
"node_modules",
|
|
17
|
-
"bower_components",
|
|
18
|
-
"test",
|
|
19
|
-
"tests"
|
|
20
|
-
]
|
|
21
|
-
}
|
package/component.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "qs",
|
|
3
|
-
"repository": "hapijs/qs",
|
|
4
|
-
"description": "query-string parser / stringifier with nesting support",
|
|
5
|
-
"version": "6.3.3",
|
|
6
|
-
"keywords": ["querystring", "query", "parser"],
|
|
7
|
-
"main": "lib/index.js",
|
|
8
|
-
"scripts": [
|
|
9
|
-
"lib/index.js",
|
|
10
|
-
"lib/parse.js",
|
|
11
|
-
"lib/stringify.js",
|
|
12
|
-
"lib/utils.js"
|
|
13
|
-
],
|
|
14
|
-
"license": "BSD-3-Clause"
|
|
15
|
-
}
|