qs 6.2.4 → 6.3.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/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ dist
package/.eslintrc CHANGED
@@ -3,37 +3,17 @@
3
3
 
4
4
  "extends": "@ljharb",
5
5
 
6
- "ignorePatterns": [
7
- "dist/",
8
- ],
9
-
10
6
  "rules": {
11
- "complexity": [2, 29],
12
- "consistent-return": 1,
13
- "func-name-matching": 0,
7
+ "complexity": [2, 25],
8
+ "consistent-return": [1],
14
9
  "id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
15
10
  "indent": [2, 4],
16
- "max-lines-per-function": 0,
17
- "max-lines": 0,
18
- "max-params": [2, 12],
19
- "max-statements": [2, 45],
20
- "multiline-comment-style": 0,
21
- "no-continue": 1,
11
+ "max-params": [2, 11],
12
+ "max-statements": [2, 42],
13
+ "no-extra-parens": [1],
14
+ "no-continue": [1],
22
15
  "no-magic-numbers": 0,
23
- "no-param-reassign": 1,
24
16
  "no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
25
- "sort-keys": 0,
26
- },
27
-
28
- "overrides": [
29
- {
30
- "files": "test/**",
31
- "rules": {
32
- "max-lines-per-function": 0,
33
- "max-statements": 0,
34
- "no-extend-native": 0,
35
- "function-paren-newline": 0,
36
- },
37
- },
38
- ],
17
+ "operator-linebreak": 1
18
+ }
39
19
  }
package/CHANGELOG.md CHANGED
@@ -1,28 +1,16 @@
1
- ## **6.2.4**
2
- - [Fix] `parse`: ignore `__proto__` keys (#428)
3
- - [Fix] `utils.merge`: avoid a crash with a null target and an array source
4
- - [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source
5
- - [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
6
- - [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
7
- - [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
8
- - [Refactor] use cached `Array.isArray`
9
- - [Docs] Clarify the need for "arrayLimit" option
10
- - [meta] fix README.md (#399)
11
- - [meta] Clean up license text so it’s properly detected as BSD-3-Clause
12
- - [meta] add FUNDING.yml
13
- - [actions] backport actions from main
14
- - [Tests] use `safer-buffer` instead of `Buffer` constructor
15
- - [Tests] remove nonexistent tape option
16
- - [Dev Deps] backport from main
17
-
18
- ## **6.2.3**
19
- - [Fix] follow `allowPrototypes` option during merge (#201, #200)
20
- - [Fix] chmod a-x
21
- - [Fix] support keys starting with brackets (#202, #200)
22
- - [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
23
-
24
- ## **6.2.2**
25
- - [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
1
+ ## **6.3.0**
2
+ - [New] Add support for RFC 1738 (#174, #173)
3
+ - [New] `stringify`: Add `serializeDate` option to customize Date serialization (#159)
4
+ - [Fix] ensure `utils.merge` handles merging two arrays
5
+ - [Refactor] only constructors should be capitalized
6
+ - [Refactor] capitalized var names are for constructors only
7
+ - [Refactor] avoid using a sparse array
8
+ - [Robustness] `formats`: cache `String#replace`
9
+ - [Dev Deps] update `browserify`, `eslint`, `@ljharb/eslint-config`; add `safe-publish-latest`
10
+ - [Tests] up to `node` `v6.8`, `v4.6`; improve test matrix
11
+ - [Tests] flesh out arrayLimit/arrayFormat tests (#107)
12
+ - [Tests] skip Object.create tests when null objects are not available
13
+ - [Tests] Turn on eslint for test files (#175)
26
14
 
27
15
  ## **6.2.1**
28
16
  - [Fix] ensure `key[]=x&key[]&key[]=y` results in 3, not 2, values
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
@@ -39,11 +39,11 @@ assert.deepEqual(qs.parse('foo[bar]=baz'), {
39
39
  });
40
40
  ```
41
41
 
42
- When using the `plainObjects` option the parsed value is returned as a plain object, created via `Object.create(null)` and as such you should be aware that prototype methods will not exist on it and a user may set those names to whatever value they like:
42
+ When using the `plainObjects` option the parsed value is returned as a null object, created via `Object.create(null)` and as such you should be aware that prototype methods will not exist on it and a user may set those names to whatever value they like:
43
43
 
44
44
  ```javascript
45
- var plainObject = qs.parse('a[hasOwnProperty]=b', { plainObjects: true });
46
- assert.deepEqual(plainObject, { a: { hasOwnProperty: 'b' } });
45
+ var nullObject = qs.parse('a[hasOwnProperty]=b', { plainObjects: true });
46
+ assert.deepEqual(nullObject, { a: { hasOwnProperty: 'b' } });
47
47
  ```
48
48
 
49
49
  By default parameters that would overwrite properties on the object prototype are ignored, if you wish to keep the data from those fields either use `plainObjects` as mentioned above, or set `allowPrototypes` to `true` which will allow user input to overwrite those properties. *WARNING* It is generally a bad idea to enable this option as it can cause problems when attempting to use the properties that have been overwritten. Always be careful with this option.
@@ -169,7 +169,7 @@ assert.deepEqual(withIndexedEmptyString, { a: ['b', '', 'c'] });
169
169
  ```
170
170
 
171
171
  **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. 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.
172
+ instead be converted to an object with the index as the key:
173
173
 
174
174
  ```javascript
175
175
  var withMaxIndex = qs.parse('a[100]=b');
@@ -245,30 +245,6 @@ var decoded = qs.parse('x=z', { decoder: function (str) {
245
245
  }})
246
246
  ```
247
247
 
248
- You can encode keys and values using different logic by using the type argument provided to the encoder:
249
-
250
- ```javascript
251
- var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) {
252
- if (type === 'key') {
253
- return // Encoded key
254
- } else if (type === 'value') {
255
- return // Encoded value
256
- }
257
- }})
258
- ```
259
-
260
- The type argument is also provided to the decoder:
261
-
262
- ```javascript
263
- var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) {
264
- if (type === 'key') {
265
- return // Decoded key
266
- } else if (type === 'value') {
267
- return // Decoded value
268
- }
269
- }})
270
- ```
271
-
272
248
  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.
273
249
 
274
250
  When arrays are stringified, by default they are given explicit indices:
@@ -314,6 +290,17 @@ The delimiter may be overridden with stringify as well:
314
290
  assert.equal(qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' }), 'a=b;c=d');
315
291
  ```
316
292
 
293
+ If you only want to override the serialization of `Date` objects, you can provide a `serializeDate` option:
294
+
295
+ ```javascript
296
+ var date = new Date(7);
297
+ assert.equal(qs.stringify({ a: date }), 'a=1970-01-01T00:00:00.007Z'.replace(/:/g, '%3A'));
298
+ assert.equal(
299
+ qs.stringify({ a: date }, { serializeDate: function (d) { return d.getTime(); } }),
300
+ 'a=7'
301
+ );
302
+ ```
303
+
317
304
  Finally, you can use the `filter` option to restrict which keys will be included in the stringified output.
318
305
  If you pass a function, it will be called for each key to obtain the replacement value. Otherwise, if you
319
306
  pass an array, it will be used to select properties and array indices for stringification:
@@ -380,7 +367,7 @@ assert.equal(nullsSkipped, 'a=b');
380
367
 
381
368
  ### Dealing with special character sets
382
369
 
383
- By default the encoding and decoding of characters is done in `utf-8`. If you
370
+ By default the encoding and decoding of characters is done in `utf-8`. If you
384
371
  wish to encode querystrings to a different character set (i.e.
385
372
  [Shift JIS](https://en.wikipedia.org/wiki/Shift_JIS)) you can use the
386
373
  [`qs-iconv`](https://github.com/martinheidegger/qs-iconv) library:
@@ -398,3 +385,14 @@ var decoder = require('qs-iconv/decoder')('shift_jis');
398
385
  var obj = qs.parse('a=%82%B1%82%F1%82%C9%82%BF%82%CD%81I', { decoder: decoder });
399
386
  assert.deepEqual(obj, { a: 'こんにちは!' });
400
387
  ```
388
+
389
+ ### RFC 3986 and RFC 1738 space encoding
390
+
391
+ RFC3986 used as default option and encodes ' ' to *%20* which is backward compatible.
392
+ In the same time, output can be stringified as per RFC1738 with ' ' equal to '+'.
393
+
394
+ ```
395
+ assert.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
396
+ assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC3986' }), 'a=b%20c');
397
+ assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC1738' }), 'a=b+c');
398
+ ```