qs 6.5.0 → 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/.eslintrc +6 -3
- package/CHANGELOG.md +30 -0
- package/README.md +88 -2
- package/dist/qs.js +210 -88
- package/lib/parse.js +87 -33
- package/lib/stringify.js +46 -14
- package/lib/utils.js +78 -42
- package/package.json +9 -8
- package/test/.eslintrc +6 -0
- package/test/parse.js +118 -5
- package/test/stringify.js +59 -6
- package/test/utils.js +55 -0
package/.eslintrc
CHANGED
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
"extends": "@ljharb",
|
|
5
5
|
|
|
6
6
|
"rules": {
|
|
7
|
-
"complexity":
|
|
7
|
+
"complexity": 0,
|
|
8
8
|
"consistent-return": 1,
|
|
9
|
+
"func-name-matching": 0,
|
|
9
10
|
"id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
|
|
10
11
|
"indent": [2, 4],
|
|
11
|
-
"max-
|
|
12
|
-
"max-
|
|
12
|
+
"max-lines-per-function": [2, { "max": 150 }],
|
|
13
|
+
"max-params": [2, 14],
|
|
14
|
+
"max-statements": [2, 52],
|
|
15
|
+
"multiline-comment-style": 0,
|
|
13
16
|
"no-continue": 1,
|
|
14
17
|
"no-magic-numbers": 0,
|
|
15
18
|
"no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
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)
|
|
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`
|
|
7
|
+
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
|
8
|
+
- [refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
|
|
9
|
+
- [Refactor] `parse`: only need to reassign the var once
|
|
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
|
|
16
|
+
|
|
17
|
+
## **6.5.2**
|
|
18
|
+
- [Fix] use `safer-buffer` instead of `Buffer` constructor
|
|
19
|
+
- [Refactor] utils: `module.exports` one thing, instead of mutating `exports` (#230)
|
|
20
|
+
- [Dev Deps] update `browserify`, `eslint`, `iconv-lite`, `safer-buffer`, `tape`, `browserify`
|
|
21
|
+
|
|
22
|
+
## **6.5.1**
|
|
23
|
+
- [Fix] Fix parsing & compacting very deep objects (#224)
|
|
24
|
+
- [Refactor] name utils functions
|
|
25
|
+
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`
|
|
26
|
+
- [Tests] up to `node` `v8.4`; use `nvm install-latest-npm` so newer npm doesn’t break older node
|
|
27
|
+
- [Tests] Use precise dist for Node.js 0.6 runtime (#225)
|
|
28
|
+
- [Tests] make 0.6 required, now that it’s passing
|
|
29
|
+
- [Tests] on `node` `v8.2`; fix npm on node 0.6
|
|
30
|
+
|
|
1
31
|
## **6.5.0**
|
|
2
32
|
- [New] add `utils.assign`
|
|
3
33
|
- [New] pass default encoder/decoder to custom encoder/decoder functions (#206)
|
package/README.md
CHANGED
|
@@ -146,6 +146,62 @@ var withDots = qs.parse('a.b=c', { allowDots: true });
|
|
|
146
146
|
assert.deepEqual(withDots, { a: { b: 'c' } });
|
|
147
147
|
```
|
|
148
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
|
+
|
|
149
205
|
### Parsing Arrays
|
|
150
206
|
|
|
151
207
|
**qs** can also parse arrays using a similar `[]` notation:
|
|
@@ -426,10 +482,40 @@ var nullsSkipped = qs.stringify({ a: 'b', c: null}, { skipNulls: true });
|
|
|
426
482
|
assert.equal(nullsSkipped, 'a=b');
|
|
427
483
|
```
|
|
428
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
|
+
|
|
429
513
|
### Dealing with special character sets
|
|
430
514
|
|
|
431
|
-
By default the encoding and decoding of characters is done in `utf-8
|
|
432
|
-
|
|
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.
|
|
433
519
|
[Shift JIS](https://en.wikipedia.org/wiki/Shift_JIS)) you can use the
|
|
434
520
|
[`qs-iconv`](https://github.com/martinheidegger/qs-iconv) library:
|
|
435
521
|
|