qs 6.5.3 → 6.6.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/.editorconfig +1 -14
- package/.eslintignore +1 -0
- package/.eslintrc +6 -22
- package/CHANGELOG.md +12 -20
- package/LICENSE +28 -0
- package/README.md +107 -56
- package/dist/qs.js +133 -44
- package/lib/formats.js +1 -1
- package/lib/parse.js +60 -9
- package/lib/stringify.js +42 -17
- package/lib/utils.js +30 -17
- package/package.json +15 -17
- package/test/.eslintrc +17 -0
- package/test/parse.js +80 -70
- package/test/stringify.js +32 -25
- package/test/utils.js +52 -28
- 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/.editorconfig
CHANGED
|
@@ -7,15 +7,11 @@ end_of_line = lf
|
|
|
7
7
|
charset = utf-8
|
|
8
8
|
trim_trailing_whitespace = true
|
|
9
9
|
insert_final_newline = true
|
|
10
|
-
max_line_length =
|
|
11
|
-
quote_type = single
|
|
10
|
+
max_line_length = 140
|
|
12
11
|
|
|
13
12
|
[test/*]
|
|
14
13
|
max_line_length = off
|
|
15
14
|
|
|
16
|
-
[LICENSE.md]
|
|
17
|
-
indent_size = off
|
|
18
|
-
|
|
19
15
|
[*.md]
|
|
20
16
|
max_line_length = off
|
|
21
17
|
|
|
@@ -32,12 +28,3 @@ indent_size = 2
|
|
|
32
28
|
[LICENSE]
|
|
33
29
|
indent_size = 2
|
|
34
30
|
max_line_length = off
|
|
35
|
-
|
|
36
|
-
[coverage/**/*]
|
|
37
|
-
indent_size = off
|
|
38
|
-
indent_style = off
|
|
39
|
-
indent = off
|
|
40
|
-
max_line_length = off
|
|
41
|
-
|
|
42
|
-
[.nycrc]
|
|
43
|
-
indent_style = tab
|
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dist
|
package/.eslintrc
CHANGED
|
@@ -3,35 +3,19 @@
|
|
|
3
3
|
|
|
4
4
|
"extends": "@ljharb",
|
|
5
5
|
|
|
6
|
-
"ignorePatterns": [
|
|
7
|
-
"dist/",
|
|
8
|
-
],
|
|
9
|
-
|
|
10
6
|
"rules": {
|
|
11
7
|
"complexity": 0,
|
|
12
8
|
"consistent-return": 1,
|
|
13
|
-
|
|
9
|
+
"func-name-matching": 0,
|
|
14
10
|
"id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
|
|
15
11
|
"indent": [2, 4],
|
|
16
|
-
"max-lines-per-function":
|
|
17
|
-
"max-params": [2,
|
|
18
|
-
"max-statements": [2,
|
|
12
|
+
"max-lines-per-function": [2, { "max": 150 }],
|
|
13
|
+
"max-params": [2, 14],
|
|
14
|
+
"max-statements": [2, 52],
|
|
19
15
|
"multiline-comment-style": 0,
|
|
20
16
|
"no-continue": 1,
|
|
21
17
|
"no-magic-numbers": 0,
|
|
22
|
-
"no-param-reassign": 1,
|
|
23
18
|
"no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
|
|
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
|
-
],
|
|
19
|
+
"operator-linebreak": [2, "before"],
|
|
20
|
+
}
|
|
37
21
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
## **6.
|
|
2
|
-
- [
|
|
3
|
-
- [
|
|
4
|
-
- [Fix] correctly parse nested arrays
|
|
1
|
+
## **6.6.0**
|
|
2
|
+
- [New] Add support for iso-8859-1, utf8 "sentinel" and numeric entities (#268)
|
|
3
|
+
- [New] move two-value combine to a `utils` function (#189)
|
|
5
4
|
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
|
|
5
|
+
- [Fix] when `parseArrays` is false, properly handle keys ending in `[]` (#260)
|
|
6
|
+
- [Fix] `stringify`: do not crash in an obscure combo of `interpretNumericEntities`, a bad custom `decoder`, & `iso-8859-1`
|
|
6
7
|
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
|
7
|
-
- [
|
|
8
|
-
- [Fix] fix for an impossible situation: when the formatter is called with a non-string value
|
|
9
|
-
- [Fix] `utils.merge`: avoid a crash with a null target and an array source
|
|
10
|
-
- [Refactor] `utils`: reduce observable [[Get]]s
|
|
11
|
-
- [Refactor] use cached `Array.isArray`
|
|
12
|
-
- [Refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
|
|
8
|
+
- [refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
|
|
13
9
|
- [Refactor] `parse`: only need to reassign the var once
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [actions] backport actions from main
|
|
21
|
-
- [Tests] always use `String(x)` over `x.toString()`
|
|
22
|
-
- [Tests] remove nonexistent tape option
|
|
23
|
-
- [Dev Deps] backport from main
|
|
10
|
+
- [Refactor] `parse`/`stringify`: clean up `charset` options checking; fix defaults
|
|
11
|
+
- [Refactor] add missing defaults
|
|
12
|
+
- [Refactor] `parse`: one less `concat` call
|
|
13
|
+
- [Refactor] `utils`: `compactQueue`: make it explicitly side-effecting
|
|
14
|
+
- [Dev Deps] update `browserify, `eslint`, `@ljharb/eslint-config`, `iconv-lite`, `safe-publish-latest`, `tape`
|
|
15
|
+
- [Tests] up to `node` `v10.10`, `v9.11`, `v8.12`, `v6.14`, `v4.9`; pin included builds to LTS
|
|
24
16
|
|
|
25
17
|
## **6.5.2**
|
|
26
18
|
- [Fix] use `safer-buffer` instead of `Buffer` constructor
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Copyright (c) 2014 Nathan LaFreniere and other contributors.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
* Redistributions of source code must retain the above copyright
|
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
|
10
|
+
documentation and/or other materials provided with the distribution.
|
|
11
|
+
* The names of any contributors may not be used to endorse or promote
|
|
12
|
+
products derived from this software without specific prior written
|
|
13
|
+
permission.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
|
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
25
|
+
|
|
26
|
+
* * *
|
|
27
|
+
|
|
28
|
+
The complete list of contributors can be found at: https://github.com/hapijs/qs/graphs/contributors
|
package/README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# qs <sup>[![Version Badge][2]][1]</sup>
|
|
2
2
|
|
|
3
|
-
[![
|
|
4
|
-
[![
|
|
5
|
-
[![dependency status][
|
|
6
|
-
[![dev dependency status][dev-deps-svg]][dev-deps-url]
|
|
3
|
+
[![Build Status][3]][4]
|
|
4
|
+
[![dependency status][5]][6]
|
|
5
|
+
[![dev dependency status][7]][8]
|
|
7
6
|
[![License][license-image]][license-url]
|
|
8
7
|
[![Downloads][downloads-image]][downloads-url]
|
|
9
8
|
|
|
10
|
-
[![npm badge][
|
|
9
|
+
[![npm badge][11]][1]
|
|
11
10
|
|
|
12
11
|
A querystring parsing and stringifying library with some added security.
|
|
13
12
|
|
|
@@ -147,6 +146,62 @@ var withDots = qs.parse('a.b=c', { allowDots: true });
|
|
|
147
146
|
assert.deepEqual(withDots, { a: { b: 'c' } });
|
|
148
147
|
```
|
|
149
148
|
|
|
149
|
+
If you have to deal with legacy browsers or services, there's
|
|
150
|
+
also support for decoding percent-encoded octets as iso-8859-1:
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
var oldCharset = qs.parse('a=%A7', { charset: 'iso-8859-1' });
|
|
154
|
+
assert.deepEqual(oldCharset, { a: '§' });
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Some services add an initial `utf8=✓` value to forms so that old
|
|
158
|
+
Internet Explorer versions are more likely to submit the form as
|
|
159
|
+
utf-8. Additionally, the server can check the value against wrong
|
|
160
|
+
encodings of the checkmark character and detect that a query string
|
|
161
|
+
or `application/x-www-form-urlencoded` body was *not* sent as
|
|
162
|
+
utf-8, eg. if the form had an `accept-charset` parameter or the
|
|
163
|
+
containing page had a different character set.
|
|
164
|
+
|
|
165
|
+
**qs** supports this mechanism via the `charsetSentinel` option.
|
|
166
|
+
If specified, the `utf8` parameter will be omitted from the
|
|
167
|
+
returned object. It will be used to switch to `iso-8859-1`/`utf-8`
|
|
168
|
+
mode depending on how the checkmark is encoded.
|
|
169
|
+
|
|
170
|
+
**Important**: When you specify both the `charset` option and the
|
|
171
|
+
`charsetSentinel` option, the `charset` will be overridden when
|
|
172
|
+
the request contains a `utf8` parameter from which the actual
|
|
173
|
+
charset can be deduced. In that sense the `charset` will behave
|
|
174
|
+
as the default charset rather than the authoritative charset.
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
var detectedAsUtf8 = qs.parse('utf8=%E2%9C%93&a=%C3%B8', {
|
|
178
|
+
charset: 'iso-8859-1',
|
|
179
|
+
charsetSentinel: true
|
|
180
|
+
});
|
|
181
|
+
assert.deepEqual(detectedAsUtf8, { a: 'ø' });
|
|
182
|
+
|
|
183
|
+
// Browsers encode the checkmark as ✓ when submitting as iso-8859-1:
|
|
184
|
+
var detectedAsIso8859_1 = qs.parse('utf8=%26%2310003%3B&a=%F8', {
|
|
185
|
+
charset: 'utf-8',
|
|
186
|
+
charsetSentinel: true
|
|
187
|
+
});
|
|
188
|
+
assert.deepEqual(detectedAsIso8859_1, { a: 'ø' });
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
If you want to decode the `&#...;` syntax to the actual character,
|
|
192
|
+
you can specify the `interpretNumericEntities` option as well:
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
var detectedAsIso8859_1 = qs.parse('a=%26%239786%3B', {
|
|
196
|
+
charset: 'iso-8859-1',
|
|
197
|
+
interpretNumericEntities: true
|
|
198
|
+
});
|
|
199
|
+
assert.deepEqual(detectedAsIso8859_1, { a: '☺' });
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
It also works when the charset has been detected in `charsetSentinel`
|
|
203
|
+
mode.
|
|
204
|
+
|
|
150
205
|
### Parsing Arrays
|
|
151
206
|
|
|
152
207
|
**qs** can also parse arrays using a similar `[]` notation:
|
|
@@ -183,7 +238,7 @@ assert.deepEqual(withIndexedEmptyString, { a: ['b', '', 'c'] });
|
|
|
183
238
|
```
|
|
184
239
|
|
|
185
240
|
**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
|
|
186
|
-
instead be converted to an object with the index as the key
|
|
241
|
+
instead be converted to an object with the index as the key:
|
|
187
242
|
|
|
188
243
|
```javascript
|
|
189
244
|
var withMaxIndex = qs.parse('a[100]=b');
|
|
@@ -268,30 +323,6 @@ var decoded = qs.parse('x=z', { decoder: function (str) {
|
|
|
268
323
|
}})
|
|
269
324
|
```
|
|
270
325
|
|
|
271
|
-
You can encode keys and values using different logic by using the type argument provided to the encoder:
|
|
272
|
-
|
|
273
|
-
```javascript
|
|
274
|
-
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) {
|
|
275
|
-
if (type === 'key') {
|
|
276
|
-
return // Encoded key
|
|
277
|
-
} else if (type === 'value') {
|
|
278
|
-
return // Encoded value
|
|
279
|
-
}
|
|
280
|
-
}})
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
The type argument is also provided to the decoder:
|
|
284
|
-
|
|
285
|
-
```javascript
|
|
286
|
-
var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) {
|
|
287
|
-
if (type === 'key') {
|
|
288
|
-
return // Decoded key
|
|
289
|
-
} else if (type === 'value') {
|
|
290
|
-
return // Decoded value
|
|
291
|
-
}
|
|
292
|
-
}})
|
|
293
|
-
```
|
|
294
|
-
|
|
295
326
|
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.
|
|
296
327
|
|
|
297
328
|
When arrays are stringified, by default they are given explicit indices:
|
|
@@ -451,10 +482,40 @@ var nullsSkipped = qs.stringify({ a: 'b', c: null}, { skipNulls: true });
|
|
|
451
482
|
assert.equal(nullsSkipped, 'a=b');
|
|
452
483
|
```
|
|
453
484
|
|
|
485
|
+
If you're communicating with legacy systems, you can switch to `iso-8859-1`
|
|
486
|
+
using the `charset` option:
|
|
487
|
+
|
|
488
|
+
```javascript
|
|
489
|
+
var iso = qs.stringify({ æ: 'æ' }, { charset: 'iso-8859-1' });
|
|
490
|
+
assert.equal(iso, '%E6=%E6');
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
Characters that don't exist in `iso-8859-1` will be converted to numeric
|
|
494
|
+
entities, similar to what browsers do:
|
|
495
|
+
|
|
496
|
+
```javascript
|
|
497
|
+
var numeric = qs.stringify({ a: '☺' }, { charset: 'iso-8859-1' });
|
|
498
|
+
assert.equal(numeric, 'a=%26%239786%3B');
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
You can use the `charsetSentinel` option to announce the character by
|
|
502
|
+
including an `utf8=✓` parameter with the proper encoding if the checkmark,
|
|
503
|
+
similar to what Ruby on Rails and others do when submitting forms.
|
|
504
|
+
|
|
505
|
+
```javascript
|
|
506
|
+
var sentinel = qs.stringify({ a: '☺' }, { charsetSentinel: true });
|
|
507
|
+
assert.equal(sentinel, 'utf8=%E2%9C%93&a=%E2%98%BA');
|
|
508
|
+
|
|
509
|
+
var isoSentinel = qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' });
|
|
510
|
+
assert.equal(isoSentinel, 'utf8=%26%2310003%3B&a=%E6');
|
|
511
|
+
```
|
|
512
|
+
|
|
454
513
|
### Dealing with special character sets
|
|
455
514
|
|
|
456
|
-
By default the encoding and decoding of characters is done in `utf-8
|
|
457
|
-
|
|
515
|
+
By default the encoding and decoding of characters is done in `utf-8`,
|
|
516
|
+
and `iso-8859-1` support is also built in via the `charset` parameter.
|
|
517
|
+
|
|
518
|
+
If you wish to encode querystrings to a different character set (i.e.
|
|
458
519
|
[Shift JIS](https://en.wikipedia.org/wiki/Shift_JIS)) you can use the
|
|
459
520
|
[`qs-iconv`](https://github.com/martinheidegger/qs-iconv) library:
|
|
460
521
|
|
|
@@ -483,28 +544,18 @@ assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC3986' }), 'a=b%20c');
|
|
|
483
544
|
assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC1738' }), 'a=b+c');
|
|
484
545
|
```
|
|
485
546
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
[
|
|
497
|
-
[
|
|
498
|
-
[deps-svg]: https://david-dm.org/ljharb/qs.svg
|
|
499
|
-
[deps-url]: https://david-dm.org/ljharb/qs
|
|
500
|
-
[dev-deps-svg]: https://david-dm.org/ljharb/qs/dev-status.svg
|
|
501
|
-
[dev-deps-url]: https://david-dm.org/ljharb/qs#info=devDependencies
|
|
502
|
-
[npm-badge-png]: https://nodei.co/npm/qs.png?downloads=true&stars=true
|
|
503
|
-
[license-image]: https://img.shields.io/npm/l/qs.svg
|
|
547
|
+
[1]: https://npmjs.org/package/qs
|
|
548
|
+
[2]: http://versionbadg.es/ljharb/qs.svg
|
|
549
|
+
[3]: https://api.travis-ci.org/ljharb/qs.svg
|
|
550
|
+
[4]: https://travis-ci.org/ljharb/qs
|
|
551
|
+
[5]: https://david-dm.org/ljharb/qs.svg
|
|
552
|
+
[6]: https://david-dm.org/ljharb/qs
|
|
553
|
+
[7]: https://david-dm.org/ljharb/qs/dev-status.svg
|
|
554
|
+
[8]: https://david-dm.org/ljharb/qs?type=dev
|
|
555
|
+
[9]: https://ci.testling.com/ljharb/qs.png
|
|
556
|
+
[10]: https://ci.testling.com/ljharb/qs
|
|
557
|
+
[11]: https://nodei.co/npm/qs.png?downloads=true&stars=true
|
|
558
|
+
[license-image]: http://img.shields.io/npm/l/qs.svg
|
|
504
559
|
[license-url]: LICENSE
|
|
505
|
-
[downloads-image]:
|
|
506
|
-
[downloads-url]:
|
|
507
|
-
[codecov-image]: https://codecov.io/gh/ljharb/qs/branch/main/graphs/badge.svg
|
|
508
|
-
[codecov-url]: https://app.codecov.io/gh/ljharb/qs/
|
|
509
|
-
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/qs
|
|
510
|
-
[actions-url]: https://github.com/ljharb/qs/actions
|
|
560
|
+
[downloads-image]: http://img.shields.io/npm/dm/qs.svg
|
|
561
|
+
[downloads-url]: http://npm-stat.com/charts.html?package=qs
|