qs 6.4.1 → 6.5.0

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/test/parse.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('parse()', function (t) {
9
9
  t.test('parses a simple string', function (st) {
@@ -231,7 +231,7 @@ test('parse()', function (t) {
231
231
  });
232
232
 
233
233
  t.test('parses buffers correctly', function (st) {
234
- var b = SaferBuffer.from('test');
234
+ var b = new Buffer('test');
235
235
  st.deepEqual(qs.parse({ a: b }), { a: b });
236
236
  st.end();
237
237
  });
@@ -256,7 +256,7 @@ test('parse()', function (t) {
256
256
  st.end();
257
257
  });
258
258
 
259
- t.test('should not throw when a native prototype has an enumerable property', function (st) {
259
+ t.test('should not throw when a native prototype has an enumerable property', { parallel: false }, function (st) {
260
260
  Object.prototype.crash = '';
261
261
  Array.prototype.crash = '';
262
262
  st.doesNotThrow(qs.parse.bind(null, 'a=b'));
@@ -301,14 +301,14 @@ test('parse()', function (t) {
301
301
  });
302
302
 
303
303
  t.test('allows disabling array parsing', function (st) {
304
- var indices = qs.parse('a[0]=b&a[1]=c', { parseArrays: false });
305
- st.deepEqual(indices, { a: { 0: 'b', 1: 'c' } });
306
- st.equal(Array.isArray(indices.a), false, 'parseArrays:false, indices case is not an array');
307
-
308
- var emptyBrackets = qs.parse('a[]=b', { parseArrays: false });
309
- st.deepEqual(emptyBrackets, { a: { 0: 'b' } });
310
- st.equal(Array.isArray(emptyBrackets.a), false, 'parseArrays:false, empty brackets case is not an array');
304
+ st.deepEqual(qs.parse('a[0]=b&a[1]=c', { parseArrays: false }), { a: { 0: 'b', 1: 'c' } });
305
+ st.end();
306
+ });
311
307
 
308
+ t.test('allows for query string prefix', function (st) {
309
+ st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' });
310
+ st.deepEqual(qs.parse('foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' });
311
+ st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: false }), { '?foo': 'bar' });
312
312
  st.end();
313
313
  });
314
314
 
@@ -480,73 +480,13 @@ test('parse()', function (t) {
480
480
 
481
481
  st.deepEqual(
482
482
  qs.parse('a[b]=c&a=toString', { plainObjects: true }),
483
- { __proto__: null, a: { __proto__: null, b: 'c', toString: true } },
483
+ { a: { b: 'c', toString: true } },
484
484
  'can overwrite prototype with plainObjects true'
485
485
  );
486
486
 
487
487
  st.end();
488
488
  });
489
489
 
490
- t.test('dunder proto is ignored', function (st) {
491
- var payload = 'categories[__proto__]=login&categories[__proto__]&categories[length]=42';
492
- var result = qs.parse(payload, { allowPrototypes: true });
493
-
494
- st.deepEqual(
495
- result,
496
- {
497
- categories: {
498
- length: '42'
499
- }
500
- },
501
- 'silent [[Prototype]] payload'
502
- );
503
-
504
- var plainResult = qs.parse(payload, { allowPrototypes: true, plainObjects: true });
505
-
506
- st.deepEqual(
507
- plainResult,
508
- {
509
- __proto__: null,
510
- categories: {
511
- __proto__: null,
512
- length: '42'
513
- }
514
- },
515
- 'silent [[Prototype]] payload: plain objects'
516
- );
517
-
518
- var query = qs.parse('categories[__proto__]=cats&categories[__proto__]=dogs&categories[some][json]=toInject', { allowPrototypes: true });
519
-
520
- st.notOk(Array.isArray(query.categories), 'is not an array');
521
- st.notOk(query.categories instanceof Array, 'is not instanceof an array');
522
- st.deepEqual(query.categories, { some: { json: 'toInject' } });
523
- st.equal(JSON.stringify(query.categories), '{"some":{"json":"toInject"}}', 'stringifies as a non-array');
524
-
525
- st.deepEqual(
526
- qs.parse('foo[__proto__][hidden]=value&foo[bar]=stuffs', { allowPrototypes: true }),
527
- {
528
- foo: {
529
- bar: 'stuffs'
530
- }
531
- },
532
- 'hidden values'
533
- );
534
-
535
- st.deepEqual(
536
- qs.parse('foo[__proto__][hidden]=value&foo[bar]=stuffs', { allowPrototypes: true, plainObjects: true }),
537
- {
538
- __proto__: null,
539
- foo: {
540
- __proto__: null,
541
- bar: 'stuffs'
542
- }
543
- },
544
- 'hidden values: plain objects'
545
- );
546
-
547
- st.end();
548
- });
549
-
550
490
  t.test('can return null objects', { skip: !Object.create }, function (st) {
551
491
  var expected = Object.create(null);
552
492
  expected.a = Object.create(null);
@@ -572,16 +512,35 @@ test('parse()', function (t) {
572
512
  result.push(parseInt(parts[1], 16));
573
513
  parts = reg.exec(str);
574
514
  }
575
- return iconv.decode(SaferBuffer.from(result), 'shift_jis').toString();
515
+ return iconv.decode(new Buffer(result), 'shift_jis').toString();
576
516
  }
577
517
  }), { 県: '大阪府' });
578
518
  st.end();
579
519
  });
580
520
 
521
+ t.test('receives the default decoder as a second argument', function (st) {
522
+ st.plan(1);
523
+ qs.parse('a', {
524
+ decoder: function (str, defaultDecoder) {
525
+ st.equal(defaultDecoder, utils.decode);
526
+ }
527
+ });
528
+ st.end();
529
+ });
530
+
581
531
  t.test('throws error with wrong decoder', function (st) {
582
- st['throws'](function () {
532
+ st.throws(function () {
583
533
  qs.parse({}, { decoder: 'string' });
584
534
  }, new TypeError('Decoder has to be a function.'));
585
535
  st.end();
586
536
  });
537
+
538
+ t.test('does not mutate the options argument', function (st) {
539
+ var options = {};
540
+ qs.parse('a[b]=true', options);
541
+ st.deepEqual(options, {});
542
+ st.end();
543
+ });
544
+
545
+ t.end();
587
546
  });
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: SaferBuffer.from('test') }), 'a=test');
330
- st.equal(qs.stringify({ a: { b: SaferBuffer.from('test') } }), 'a%5Bb%5D=test');
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,15 +463,25 @@ 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
- st['throws'](function () {
477
+ st.throws(function () {
458
478
  qs.stringify({}, { encoder: 'string' });
459
479
  }, new TypeError('Encoder has to be a function.'));
460
480
  st.end();
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: SaferBuffer.from([1]) }, {
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
 
@@ -490,7 +504,7 @@ test('stringify()', function (t) {
490
504
  mutatedDate.toISOString = function () {
491
505
  throw new SyntaxError();
492
506
  };
493
- st['throws'](function () {
507
+ st.throws(function () {
494
508
  mutatedDate.toISOString();
495
509
  }, SyntaxError);
496
510
  st.equal(
@@ -515,27 +529,24 @@ 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
547
  ['UFO1234', false, 1234, null, {}, []].forEach(
537
548
  function (format) {
538
- st['throws'](
549
+ st.throws(
539
550
  function () {
540
551
  qs.stringify({ a: 'b c' }, { format: format });
541
552
  },
@@ -574,23 +585,10 @@ test('stringify()', function (t) {
574
585
  st.end();
575
586
  });
576
587
 
577
- t.test('strictNullHandling works with custom filter', function (st) {
578
- var filter = function (prefix, value) {
579
- return value;
580
- };
581
-
582
- var options = { strictNullHandling: true, filter: filter };
583
- st.equal(qs.stringify({ key: null }, options), 'key');
584
- st.end();
585
- });
586
-
587
- t.test('strictNullHandling works with null serializeDate', function (st) {
588
- var serializeDate = function () {
589
- return null;
590
- };
591
- var options = { strictNullHandling: true, serializeDate: serializeDate };
592
- var date = new Date();
593
- 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, {});
594
592
  st.end();
595
593
  });
596
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
- var noOptionsNonObjectSource = utils.merge({ foo: 'baz' }, 'bar');
26
- t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });
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
  });
@@ -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
@@ -1,13 +0,0 @@
1
- {
2
- "all": true,
3
- "check-coverage": false,
4
- "reporter": ["text-summary", "text", "html", "json"],
5
- "lines": 86,
6
- "statements": 85.93,
7
- "functions": 82.43,
8
- "branches": 76.06,
9
- "exclude": [
10
- "coverage",
11
- "dist"
12
- ]
13
- }
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.4.1",
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
- }