qs 6.4.0 → 6.4.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 ADDED
@@ -0,0 +1,44 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 4
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+ max_line_length = 160
11
+ quote_type = single
12
+
13
+ [test/*]
14
+ max_line_length = off
15
+
16
+ [*.md]
17
+ indent_size = off
18
+ max_line_length = off
19
+
20
+ [*.json]
21
+ max_line_length = off
22
+
23
+ [Makefile]
24
+ max_line_length = off
25
+
26
+ [CHANGELOG.md]
27
+ indent_style = space
28
+ indent_size = 2
29
+
30
+ [LICENSE]
31
+ indent_size = 2
32
+ max_line_length = off
33
+
34
+ [coverage/**/*]
35
+ indent_size = off
36
+ indent_style = off
37
+ indent = off
38
+ max_line_length = off
39
+
40
+ [dist/*]
41
+ max_line_length = off
42
+
43
+ [.nycrc]
44
+ indent_style = tab
package/.eslintrc CHANGED
@@ -3,16 +3,35 @@
3
3
 
4
4
  "extends": "@ljharb",
5
5
 
6
+ "ignorePatterns": [
7
+ "dist/",
8
+ ],
9
+
6
10
  "rules": {
7
- "complexity": [2, 26],
11
+ "complexity": [2, 29],
8
12
  "consistent-return": 1,
13
+ "func-name-matching": 0,
9
14
  "id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
10
15
  "indent": [2, 4],
16
+ "max-lines-per-function": 0,
11
17
  "max-params": [2, 12],
12
- "max-statements": [2, 43],
18
+ "max-statements": [2, 45],
19
+ "multiline-comment-style": 0,
13
20
  "no-continue": 1,
14
21
  "no-magic-numbers": 0,
22
+ "no-param-reassign": 1,
15
23
  "no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
16
- "operator-linebreak": [2, "after"],
17
- }
24
+ },
25
+
26
+ "overrides": [
27
+ {
28
+ "files": "test/**",
29
+ "rules": {
30
+ "max-lines-per-function": 0,
31
+ "max-statements": 0,
32
+ "no-extend-native": 0,
33
+ "function-paren-newline": 0,
34
+ },
35
+ },
36
+ ],
18
37
  }
@@ -0,0 +1,12 @@
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 ADDED
@@ -0,0 +1,13 @@
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/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## **6.4.1**
2
+ - [Fix] `parse`: ignore `__proto__` keys (#428)
3
+ - [Fix] fix for an impossible situation: when the formatter is called with a non-string value
4
+ - [Fix] use `safer-buffer` instead of `Buffer` constructor
5
+ - [Fix] `utils.merge`: avoid a crash with a null target and an array source
6
+ - [Fix]` `utils.merge`: avoid a crash with a null target and a truthy non-array source
7
+ - [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
8
+ - [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
9
+ - [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
10
+ - [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
11
+ - [Refactor] use cached `Array.isArray`
12
+ - [Refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
13
+ - [readme] remove travis badge; add github actions/codecov badges; update URLs
14
+ - [Docs] Clarify the need for "arrayLimit" option
15
+ - [meta] fix README.md (#399)
16
+ - [meta] Clean up license text so it’s properly detected as BSD-3-Clause
17
+ - [meta] add FUNDING.yml
18
+ - [actions] backport actions from main
19
+ - [Tests] remove nonexistent tape option
20
+ - [Dev Deps] backport from main
21
+
1
22
  ## **6.4.0**
2
23
  - [New] `qs.stringify`: add `encodeValuesOnly` option
3
24
  - [Fix] follow `allowPrototypes` option during merge (#201, #201)
package/LICENSE.md ADDED
@@ -0,0 +1,29 @@
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/README.md CHANGED
@@ -1,4 +1,13 @@
1
- # qs
1
+ # qs <sup>[![Version Badge][2]][1]</sup>
2
+
3
+ [![github actions][actions-image]][actions-url]
4
+ [![coverage][codecov-image]][codecov-url]
5
+ [![dependency status][deps-svg]][deps-url]
6
+ [![dev dependency status][dev-deps-svg]][dev-deps-url]
7
+ [![License][license-image]][license-url]
8
+ [![Downloads][downloads-image]][downloads-url]
9
+
10
+ [![npm badge][npm-badge-png]][package-url]
2
11
 
3
12
  A querystring parsing and stringifying library with some added security.
4
13
 
@@ -169,7 +178,7 @@ assert.deepEqual(withIndexedEmptyString, { a: ['b', '', 'c'] });
169
178
  ```
170
179
 
171
180
  **qs** will also limit specifying indices in an array to a maximum index of `20`. Any array members with an index of greater than `20` will
172
- instead be converted to an object with the index as the key:
181
+ instead be converted to an object with the index as the key. This is needed to handle cases when someone sent, for example, `a[999999999]` and it will take significant time to iterate over this huge array.
173
182
 
174
183
  ```javascript
175
184
  var withMaxIndex = qs.parse('a[100]=b');
@@ -254,6 +263,30 @@ var decoded = qs.parse('x=z', { decoder: function (str) {
254
263
  }})
255
264
  ```
256
265
 
266
+ You can encode keys and values using different logic by using the type argument provided to the encoder:
267
+
268
+ ```javascript
269
+ var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) {
270
+ if (type === 'key') {
271
+ return // Encoded key
272
+ } else if (type === 'value') {
273
+ return // Encoded value
274
+ }
275
+ }})
276
+ ```
277
+
278
+ The type argument is also provided to the decoder:
279
+
280
+ ```javascript
281
+ var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) {
282
+ if (type === 'key') {
283
+ return // Decoded key
284
+ } else if (type === 'value') {
285
+ return // Decoded value
286
+ }
287
+ }})
288
+ ```
289
+
257
290
  Examples beyond this point will be shown as though the output is not URI encoded for clarity. Please note that the return values in these cases *will* be URI encoded during real usage.
258
291
 
259
292
  When arrays are stringified, by default they are given explicit indices:
@@ -438,3 +471,29 @@ assert.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
438
471
  assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC3986' }), 'a=b%20c');
439
472
  assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC1738' }), 'a=b+c');
440
473
  ```
474
+
475
+ ## Security
476
+
477
+ Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
478
+
479
+ ## qs for enterprise
480
+
481
+ Available as part of the Tidelift Subscription
482
+
483
+ The maintainers of qs and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-qs?utm_source=npm-qs&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
484
+
485
+ [package-url]: https://npmjs.org/package/qs
486
+ [npm-version-svg]: https://versionbadg.es/ljharb/qs.svg
487
+ [deps-svg]: https://david-dm.org/ljharb/qs.svg
488
+ [deps-url]: https://david-dm.org/ljharb/qs
489
+ [dev-deps-svg]: https://david-dm.org/ljharb/qs/dev-status.svg
490
+ [dev-deps-url]: https://david-dm.org/ljharb/qs#info=devDependencies
491
+ [npm-badge-png]: https://nodei.co/npm/qs.png?downloads=true&stars=true
492
+ [license-image]: https://img.shields.io/npm/l/qs.svg
493
+ [license-url]: LICENSE
494
+ [downloads-image]: https://img.shields.io/npm/dm/qs.svg
495
+ [downloads-url]: https://npm-stat.com/charts.html?package=qs
496
+ [codecov-image]: https://codecov.io/gh/ljharb/qs/branch/main/graphs/badge.svg
497
+ [codecov-url]: https://app.codecov.io/gh/ljharb/qs/
498
+ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/qs
499
+ [actions-url]: https://github.com/ljharb/qs/actions
package/bower.json ADDED
@@ -0,0 +1,21 @@
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 ADDED
@@ -0,0 +1,15 @@
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
+ }
package/dist/qs.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
1
+ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
2
  'use strict';
3
3
 
4
4
  var replace = String.prototype.replace;
@@ -11,7 +11,7 @@ module.exports = {
11
11
  return replace.call(value, percentTwenties, '+');
12
12
  },
13
13
  RFC3986: function (value) {
14
- return value;
14
+ return String(value);
15
15
  }
16
16
  },
17
17
  RFC1738: 'RFC1738',
@@ -84,23 +84,25 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
84
84
  var root = chain.shift();
85
85
 
86
86
  var obj;
87
- if (root === '[]') {
87
+ if (root === '[]' && options.parseArrays) {
88
88
  obj = [];
89
89
  obj = obj.concat(parseObject(chain, val, options));
90
90
  } else {
91
91
  obj = options.plainObjects ? Object.create(null) : {};
92
92
  var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
93
93
  var index = parseInt(cleanRoot, 10);
94
- if (
95
- !isNaN(index) &&
96
- root !== cleanRoot &&
97
- String(index) === cleanRoot &&
98
- index >= 0 &&
99
- (options.parseArrays && index <= options.arrayLimit)
94
+ if (!options.parseArrays && cleanRoot === '') {
95
+ obj = { 0: val };
96
+ } else if (
97
+ !isNaN(index)
98
+ && root !== cleanRoot
99
+ && String(index) === cleanRoot
100
+ && index >= 0
101
+ && (options.parseArrays && index <= options.arrayLimit)
100
102
  ) {
101
103
  obj = [];
102
104
  obj[index] = parseObject(chain, val, options);
103
- } else {
105
+ } else if (cleanRoot !== '__proto__') {
104
106
  obj[cleanRoot] = parseObject(chain, val, options);
105
107
  }
106
108
  }
@@ -130,8 +132,7 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
130
132
 
131
133
  var keys = [];
132
134
  if (parent) {
133
- // If we aren't using plain objects, optionally prefix keys
134
- // that would overwrite object prototype properties
135
+ // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
135
136
  if (!options.plainObjects && has.call(Object.prototype, parent)) {
136
137
  if (!options.allowPrototypes) {
137
138
  return;
@@ -207,17 +208,23 @@ var utils = require('./utils');
207
208
  var formats = require('./formats');
208
209
 
209
210
  var arrayPrefixGenerators = {
210
- brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
211
+ brackets: function brackets(prefix) {
211
212
  return prefix + '[]';
212
213
  },
213
- indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
214
+ indices: function indices(prefix, key) {
214
215
  return prefix + '[' + key + ']';
215
216
  },
216
- repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
217
+ repeat: function repeat(prefix) {
217
218
  return prefix;
218
219
  }
219
220
  };
220
221
 
222
+ var isArray = Array.isArray;
223
+ var push = Array.prototype.push;
224
+ var pushToArray = function (arr, valueOrArray) {
225
+ push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
226
+ };
227
+
221
228
  var toISO = Date.prototype.toISOString;
222
229
 
223
230
  var defaults = {
@@ -225,14 +232,14 @@ var defaults = {
225
232
  encode: true,
226
233
  encoder: utils.encode,
227
234
  encodeValuesOnly: false,
228
- serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
235
+ serializeDate: function serializeDate(date) {
229
236
  return toISO.call(date);
230
237
  },
231
238
  skipNulls: false,
232
239
  strictNullHandling: false
233
240
  };
234
241
 
235
- var stringify = function stringify( // eslint-disable-line func-name-matching
242
+ var stringify = function stringify(
236
243
  object,
237
244
  prefix,
238
245
  generateArrayPrefix,
@@ -251,7 +258,9 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
251
258
  obj = filter(prefix, obj);
252
259
  } else if (obj instanceof Date) {
253
260
  obj = serializeDate(obj);
254
- } else if (obj === null) {
261
+ }
262
+
263
+ if (obj === null) {
255
264
  if (strictNullHandling) {
256
265
  return encoder && !encodeValuesOnly ? encoder(prefix) : prefix;
257
266
  }
@@ -274,7 +283,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
274
283
  }
275
284
 
276
285
  var objKeys;
277
- if (Array.isArray(filter)) {
286
+ if (isArray(filter)) {
278
287
  objKeys = filter;
279
288
  } else {
280
289
  var keys = Object.keys(obj);
@@ -288,8 +297,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
288
297
  continue;
289
298
  }
290
299
 
291
- if (Array.isArray(obj)) {
292
- values = values.concat(stringify(
300
+ if (isArray(obj)) {
301
+ pushToArray(values, stringify(
293
302
  obj[key],
294
303
  generateArrayPrefix(prefix, key),
295
304
  generateArrayPrefix,
@@ -304,7 +313,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
304
313
  encodeValuesOnly
305
314
  ));
306
315
  } else {
307
- values = values.concat(stringify(
316
+ pushToArray(values, stringify(
308
317
  obj[key],
309
318
  prefix + (allowDots ? '.' + key : '[' + key + ']'),
310
319
  generateArrayPrefix,
@@ -328,7 +337,7 @@ module.exports = function (object, opts) {
328
337
  var obj = object;
329
338
  var options = opts || {};
330
339
 
331
- if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
340
+ if (options.encoder !== null && typeof options.encoder !== 'undefined' && typeof options.encoder !== 'function') {
332
341
  throw new TypeError('Encoder has to be a function.');
333
342
  }
334
343
 
@@ -342,7 +351,7 @@ module.exports = function (object, opts) {
342
351
  var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
343
352
  var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly;
344
353
  if (typeof options.format === 'undefined') {
345
- options.format = formats.default;
354
+ options.format = formats['default'];
346
355
  } else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
347
356
  throw new TypeError('Unknown format option provided.');
348
357
  }
@@ -353,7 +362,7 @@ module.exports = function (object, opts) {
353
362
  if (typeof options.filter === 'function') {
354
363
  filter = options.filter;
355
364
  obj = filter('', obj);
356
- } else if (Array.isArray(options.filter)) {
365
+ } else if (isArray(options.filter)) {
357
366
  filter = options.filter;
358
367
  objKeys = filter;
359
368
  }
@@ -389,8 +398,7 @@ module.exports = function (object, opts) {
389
398
  if (skipNulls && obj[key] === null) {
390
399
  continue;
391
400
  }
392
-
393
- keys = keys.concat(stringify(
401
+ pushToArray(keys, stringify(
394
402
  obj[key],
395
403
  key,
396
404
  generateArrayPrefix,
@@ -442,8 +450,8 @@ exports.merge = function (target, source, options) {
442
450
  if (typeof source !== 'object') {
443
451
  if (Array.isArray(target)) {
444
452
  target.push(source);
445
- } else if (typeof target === 'object') {
446
- if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
453
+ } else if (target && typeof target === 'object') {
454
+ if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
447
455
  target[source] = true;
448
456
  }
449
457
  } else {
@@ -453,7 +461,7 @@ exports.merge = function (target, source, options) {
453
461
  return target;
454
462
  }
455
463
 
456
- if (typeof target !== 'object') {
464
+ if (!target || typeof target !== 'object') {
457
465
  return [target].concat(source);
458
466
  }
459
467
 
@@ -511,13 +519,13 @@ exports.encode = function (str) {
511
519
  var c = string.charCodeAt(i);
512
520
 
513
521
  if (
514
- c === 0x2D || // -
515
- c === 0x2E || // .
516
- c === 0x5F || // _
517
- c === 0x7E || // ~
518
- (c >= 0x30 && c <= 0x39) || // 0-9
519
- (c >= 0x41 && c <= 0x5A) || // a-z
520
- (c >= 0x61 && c <= 0x7A) // A-Z
522
+ c === 0x2D // -
523
+ || c === 0x2E // .
524
+ || c === 0x5F // _
525
+ || c === 0x7E // ~
526
+ || (c >= 0x30 && c <= 0x39) // 0-9
527
+ || (c >= 0x41 && c <= 0x5A) // a-z
528
+ || (c >= 0x61 && c <= 0x7A) // A-Z
521
529
  ) {
522
530
  out += string.charAt(i);
523
531
  continue;
@@ -540,7 +548,11 @@ exports.encode = function (str) {
540
548
 
541
549
  i += 1;
542
550
  c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
543
- out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len
551
+ /* eslint operator-linebreak: [2, "before"] */
552
+ out += hexTable[0xF0 | (c >> 18)]
553
+ + hexTable[0x80 | ((c >> 12) & 0x3F)]
554
+ + hexTable[0x80 | ((c >> 6) & 0x3F)]
555
+ + hexTable[0x80 | (c & 0x3F)];
544
556
  }
545
557
 
546
558
  return out;
@@ -594,4 +606,4 @@ exports.isBuffer = function (obj) {
594
606
  };
595
607
 
596
608
  },{}]},{},[2])(2)
597
- });
609
+ });
package/lib/formats.js CHANGED
@@ -10,7 +10,7 @@ module.exports = {
10
10
  return replace.call(value, percentTwenties, '+');
11
11
  },
12
12
  RFC3986: function (value) {
13
- return value;
13
+ return String(value);
14
14
  }
15
15
  },
16
16
  RFC1738: 'RFC1738',
package/lib/parse.js CHANGED
@@ -50,23 +50,25 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
50
50
  var root = chain.shift();
51
51
 
52
52
  var obj;
53
- if (root === '[]') {
53
+ if (root === '[]' && options.parseArrays) {
54
54
  obj = [];
55
55
  obj = obj.concat(parseObject(chain, val, options));
56
56
  } else {
57
57
  obj = options.plainObjects ? Object.create(null) : {};
58
58
  var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
59
59
  var index = parseInt(cleanRoot, 10);
60
- if (
61
- !isNaN(index) &&
62
- root !== cleanRoot &&
63
- String(index) === cleanRoot &&
64
- index >= 0 &&
65
- (options.parseArrays && index <= options.arrayLimit)
60
+ if (!options.parseArrays && cleanRoot === '') {
61
+ obj = { 0: val };
62
+ } else if (
63
+ !isNaN(index)
64
+ && root !== cleanRoot
65
+ && String(index) === cleanRoot
66
+ && index >= 0
67
+ && (options.parseArrays && index <= options.arrayLimit)
66
68
  ) {
67
69
  obj = [];
68
70
  obj[index] = parseObject(chain, val, options);
69
- } else {
71
+ } else if (cleanRoot !== '__proto__') {
70
72
  obj[cleanRoot] = parseObject(chain, val, options);
71
73
  }
72
74
  }
@@ -96,8 +98,7 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
96
98
 
97
99
  var keys = [];
98
100
  if (parent) {
99
- // If we aren't using plain objects, optionally prefix keys
100
- // that would overwrite object prototype properties
101
+ // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
101
102
  if (!options.plainObjects && has.call(Object.prototype, parent)) {
102
103
  if (!options.allowPrototypes) {
103
104
  return;