Agregado toping en los menus
This commit is contained in:
3
node_modules/qs/.editorconfig
generated
vendored
3
node_modules/qs/.editorconfig
generated
vendored
@@ -41,3 +41,6 @@ max_line_length = off
|
||||
|
||||
[.nycrc]
|
||||
indent_style = tab
|
||||
|
||||
[tea.yaml]
|
||||
indent_size = 2
|
||||
|
||||
4
node_modules/qs/.eslintrc
generated
vendored
4
node_modules/qs/.eslintrc
generated
vendored
@@ -14,8 +14,8 @@
|
||||
"id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
|
||||
"indent": [2, 4],
|
||||
"max-lines-per-function": [2, { "max": 150 }],
|
||||
"max-params": [2, 16],
|
||||
"max-statements": [2, 53],
|
||||
"max-params": [2, 18],
|
||||
"max-statements": [2, 100],
|
||||
"multiline-comment-style": 0,
|
||||
"no-continue": 1,
|
||||
"no-magic-numbers": 0,
|
||||
|
||||
64
node_modules/qs/CHANGELOG.md
generated
vendored
64
node_modules/qs/CHANGELOG.md
generated
vendored
@@ -1,4 +1,58 @@
|
||||
## **6.11.0
|
||||
## **6.13.0**
|
||||
- [New] `parse`: add `strictDepth` option (#511)
|
||||
- [Tests] use `npm audit` instead of `aud`
|
||||
|
||||
## **6.12.3**
|
||||
- [Fix] `parse`: properly account for `strictNullHandling` when `allowEmptyArrays`
|
||||
- [meta] fix changelog indentation
|
||||
|
||||
## **6.12.2**
|
||||
- [Fix] `parse`: parse encoded square brackets (#506)
|
||||
- [readme] add CII best practices badge
|
||||
|
||||
## **6.12.1**
|
||||
- [Fix] `parse`: Disable `decodeDotInKeys` by default to restore previous behavior (#501)
|
||||
- [Performance] `utils`: Optimize performance under large data volumes, reduce memory usage, and speed up processing (#502)
|
||||
- [Refactor] `utils`: use `+=`
|
||||
- [Tests] increase coverage
|
||||
|
||||
## **6.12.0**
|
||||
|
||||
- [New] `parse`/`stringify`: add `decodeDotInKeys`/`encodeDotKeys` options (#488)
|
||||
- [New] `parse`: add `duplicates` option
|
||||
- [New] `parse`/`stringify`: add `allowEmptyArrays` option to allow [] in object values (#487)
|
||||
- [Refactor] `parse`/`stringify`: move allowDots config logic to its own variable
|
||||
- [Refactor] `stringify`: move option-handling code into `normalizeStringifyOptions`
|
||||
- [readme] update readme, add logos (#484)
|
||||
- [readme] `stringify`: clarify default `arrayFormat` behavior
|
||||
- [readme] fix line wrapping
|
||||
- [readme] remove dead badges
|
||||
- [Deps] update `side-channel`
|
||||
- [meta] make the dist build 50% smaller
|
||||
- [meta] add `sideEffects` flag
|
||||
- [meta] run build in prepack, not prepublish
|
||||
- [Tests] `parse`: remove useless tests; add coverage
|
||||
- [Tests] `stringify`: increase coverage
|
||||
- [Tests] use `mock-property`
|
||||
- [Tests] `stringify`: improve coverage
|
||||
- [Dev Deps] update `@ljharb/eslint-config `, `aud`, `has-override-mistake`, `has-property-descriptors`, `mock-property`, `npmignore`, `object-inspect`, `tape`
|
||||
- [Dev Deps] pin `glob`, since v10.3.8+ requires a broken `jackspeak`
|
||||
- [Dev Deps] pin `jackspeak` since 2.1.2+ depends on npm aliases, which kill the install process in npm < 6
|
||||
|
||||
## **6.11.2**
|
||||
- [Fix] `parse`: Fix parsing when the global Object prototype is frozen (#473)
|
||||
- [Tests] add passing test cases with empty keys (#473)
|
||||
|
||||
## **6.11.1**
|
||||
- [Fix] `stringify`: encode comma values more consistently (#463)
|
||||
- [readme] add usage of `filter` option for injecting custom serialization, i.e. of custom types (#447)
|
||||
- [meta] remove extraneous code backticks (#457)
|
||||
- [meta] fix changelog markdown
|
||||
- [actions] update checkout action
|
||||
- [actions] restrict action permissions
|
||||
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape`
|
||||
|
||||
## **6.11.0**
|
||||
- [New] [Fix] `stringify`: revert 0e903c0; add `commaRoundTrip` option (#442)
|
||||
- [readme] fix version badge
|
||||
|
||||
@@ -238,7 +292,7 @@
|
||||
|
||||
## **6.5.3**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Fix]` `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] correctly parse nested arrays
|
||||
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
|
||||
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
||||
@@ -291,7 +345,7 @@
|
||||
- [Fix] fix for an impossible situation: when the formatter is called with a non-string value
|
||||
- [Fix] use `safer-buffer` instead of `Buffer` constructor
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and an array source
|
||||
- [Fix]` `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
|
||||
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
||||
- [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
|
||||
@@ -320,7 +374,7 @@
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Fix] fix for an impossible situation: when the formatter is called with a non-string value
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and an array source
|
||||
- [Fix]` `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
|
||||
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
||||
- [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
|
||||
@@ -407,7 +461,7 @@
|
||||
- [New] add "encoder" and "decoder" options, for custom param encoding/decoding (#160)
|
||||
- [Fix] fix compacting of nested sparse arrays (#150)
|
||||
|
||||
## **6.1.2
|
||||
## **6.1.2**
|
||||
- [Fix] follow `allowPrototypes` option during merge (#201, #200)
|
||||
- [Fix] chmod a-x
|
||||
- [Fix] support keys starting with brackets (#202, #200)
|
||||
|
||||
182
node_modules/qs/README.md
generated
vendored
182
node_modules/qs/README.md
generated
vendored
@@ -1,11 +1,14 @@
|
||||
<p align="center">
|
||||
<img alt="qs" src="./logos/banner_default.png" width="800" />
|
||||
</p>
|
||||
|
||||
# qs <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||
|
||||
[![github actions][actions-image]][actions-url]
|
||||
[![coverage][codecov-image]][codecov-url]
|
||||
[![dependency status][deps-svg]][deps-url]
|
||||
[![dev dependency status][dev-deps-svg]][dev-deps-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
[](https://bestpractices.coreinfrastructure.org/projects/9058)
|
||||
|
||||
[![npm badge][npm-badge-png]][package-url]
|
||||
|
||||
@@ -53,7 +56,9 @@ var nullObject = qs.parse('a[hasOwnProperty]=b', { plainObjects: true });
|
||||
assert.deepEqual(nullObject, { a: { hasOwnProperty: 'b' } });
|
||||
```
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
```javascript
|
||||
var protoObject = qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true });
|
||||
@@ -80,8 +85,8 @@ assert.deepEqual(qs.parse('foo[bar][baz]=foobarbaz'), {
|
||||
});
|
||||
```
|
||||
|
||||
By default, when nesting objects **qs** will only parse up to 5 children deep. This means if you attempt to parse a string like
|
||||
`'a[b][c][d][e][f][g][h][i]=j'` your resulting object will be:
|
||||
By default, when nesting objects **qs** will only parse up to 5 children deep.
|
||||
This means if you attempt to parse a string like `'a[b][c][d][e][f][g][h][i]=j'` your resulting object will be:
|
||||
|
||||
```javascript
|
||||
var expected = {
|
||||
@@ -110,7 +115,18 @@ var deep = qs.parse('a[b][c][d][e][f][g][h][i]=j', { depth: 1 });
|
||||
assert.deepEqual(deep, { a: { b: { '[c][d][e][f][g][h][i]': 'j' } } });
|
||||
```
|
||||
|
||||
The depth limit helps mitigate abuse when **qs** is used to parse user input, and it is recommended to keep it a reasonably small number.
|
||||
You can configure **qs** to throw an error when parsing nested input beyond this depth using the `strictDepth` option (defaulted to false):
|
||||
|
||||
```javascript
|
||||
try {
|
||||
qs.parse('a[b][c][d][e][f][g][h][i]=j', { depth: 1, strictDepth: true });
|
||||
} catch (err) {
|
||||
assert(err instanceof RangeError);
|
||||
assert.strictEqual(err.message, 'Input depth exceeded depth option of 1 and strictDepth is true');
|
||||
}
|
||||
```
|
||||
|
||||
The depth limit helps mitigate abuse when **qs** is used to parse user input, and it is recommended to keep it a reasonably small number. The strictDepth option adds a layer of protection by throwing an error when the limit is exceeded, allowing you to catch and handle such cases.
|
||||
|
||||
For similar reasons, by default **qs** will only parse up to 1000 parameters. This can be overridden by passing a `parameterLimit` option:
|
||||
|
||||
@@ -147,32 +163,44 @@ var withDots = qs.parse('a.b=c', { allowDots: true });
|
||||
assert.deepEqual(withDots, { a: { b: 'c' } });
|
||||
```
|
||||
|
||||
If you have to deal with legacy browsers or services, there's
|
||||
also support for decoding percent-encoded octets as iso-8859-1:
|
||||
Option `decodeDotInKeys` can be used to decode dots in keys
|
||||
Note: it implies `allowDots`, so `parse` will error if you set `decodeDotInKeys` to `true`, and `allowDots` to `false`.
|
||||
|
||||
```javascript
|
||||
var withDots = qs.parse('name%252Eobj.first=John&name%252Eobj.last=Doe', { decodeDotInKeys: true });
|
||||
assert.deepEqual(withDots, { 'name.obj': { first: 'John', last: 'Doe' }});
|
||||
```
|
||||
|
||||
Option `allowEmptyArrays` can be used to allowing empty array values in object
|
||||
```javascript
|
||||
var withEmptyArrays = qs.parse('foo[]&bar=baz', { allowEmptyArrays: true });
|
||||
assert.deepEqual(withEmptyArrays, { foo: [], bar: 'baz' });
|
||||
```
|
||||
|
||||
Option `duplicates` can be used to change the behavior when duplicate keys are encountered
|
||||
```javascript
|
||||
assert.deepEqual(qs.parse('foo=bar&foo=baz'), { foo: ['bar', 'baz'] });
|
||||
assert.deepEqual(qs.parse('foo=bar&foo=baz', { duplicates: 'combine' }), { foo: ['bar', 'baz'] });
|
||||
assert.deepEqual(qs.parse('foo=bar&foo=baz', { duplicates: 'first' }), { foo: 'bar' });
|
||||
assert.deepEqual(qs.parse('foo=bar&foo=baz', { duplicates: 'last' }), { foo: 'baz' });
|
||||
```
|
||||
|
||||
If you have to deal with legacy browsers or services, there's also support for decoding percent-encoded octets as iso-8859-1:
|
||||
|
||||
```javascript
|
||||
var oldCharset = qs.parse('a=%A7', { charset: 'iso-8859-1' });
|
||||
assert.deepEqual(oldCharset, { a: '§' });
|
||||
```
|
||||
|
||||
Some services add an initial `utf8=✓` value to forms so that old
|
||||
Internet Explorer versions are more likely to submit the form as
|
||||
utf-8. Additionally, the server can check the value against wrong
|
||||
encodings of the checkmark character and detect that a query string
|
||||
or `application/x-www-form-urlencoded` body was *not* sent as
|
||||
utf-8, eg. if the form had an `accept-charset` parameter or the
|
||||
containing page had a different character set.
|
||||
Some services add an initial `utf8=✓` value to forms so that old Internet Explorer versions are more likely to submit the form as utf-8.
|
||||
Additionally, the server can check the value against wrong encodings of the checkmark character and detect that a query string or `application/x-www-form-urlencoded` body was *not* sent as utf-8, eg. if the form had an `accept-charset` parameter or the containing page had a different character set.
|
||||
|
||||
**qs** supports this mechanism via the `charsetSentinel` option.
|
||||
If specified, the `utf8` parameter will be omitted from the
|
||||
returned object. It will be used to switch to `iso-8859-1`/`utf-8`
|
||||
mode depending on how the checkmark is encoded.
|
||||
If specified, the `utf8` parameter will be omitted from the returned object.
|
||||
It will be used to switch to `iso-8859-1`/`utf-8` mode depending on how the checkmark is encoded.
|
||||
|
||||
**Important**: When you specify both the `charset` option and the
|
||||
`charsetSentinel` option, the `charset` will be overridden when
|
||||
the request contains a `utf8` parameter from which the actual
|
||||
charset can be deduced. In that sense the `charset` will behave
|
||||
as the default charset rather than the authoritative charset.
|
||||
**Important**: When you specify both the `charset` option and the `charsetSentinel` option, the `charset` will be overridden when the request contains a `utf8` parameter from which the actual charset can be deduced.
|
||||
In that sense the `charset` will behave as the default charset rather than the authoritative charset.
|
||||
|
||||
```javascript
|
||||
var detectedAsUtf8 = qs.parse('utf8=%E2%9C%93&a=%C3%B8', {
|
||||
@@ -189,8 +217,7 @@ var detectedAsIso8859_1 = qs.parse('utf8=%26%2310003%3B&a=%F8', {
|
||||
assert.deepEqual(detectedAsIso8859_1, { a: 'ø' });
|
||||
```
|
||||
|
||||
If you want to decode the `&#...;` syntax to the actual character,
|
||||
you can specify the `interpretNumericEntities` option as well:
|
||||
If you want to decode the `&#...;` syntax to the actual character, you can specify the `interpretNumericEntities` option as well:
|
||||
|
||||
```javascript
|
||||
var detectedAsIso8859_1 = qs.parse('a=%26%239786%3B', {
|
||||
@@ -200,8 +227,7 @@ var detectedAsIso8859_1 = qs.parse('a=%26%239786%3B', {
|
||||
assert.deepEqual(detectedAsIso8859_1, { a: '☺' });
|
||||
```
|
||||
|
||||
It also works when the charset has been detected in `charsetSentinel`
|
||||
mode.
|
||||
It also works when the charset has been detected in `charsetSentinel` mode.
|
||||
|
||||
### Parsing Arrays
|
||||
|
||||
@@ -219,9 +245,8 @@ var withIndexes = qs.parse('a[1]=c&a[0]=b');
|
||||
assert.deepEqual(withIndexes, { a: ['b', 'c'] });
|
||||
```
|
||||
|
||||
Note that the only difference between an index in an array and a key in an object is that the value between the brackets must be a number
|
||||
to create an array. When creating arrays with specific indices, **qs** will compact a sparse array to only the existing values preserving
|
||||
their order:
|
||||
Note that the only difference between an index in an array and a key in an object is that the value between the brackets must be a number to create an array.
|
||||
When creating arrays with specific indices, **qs** will compact a sparse array to only the existing values preserving their order:
|
||||
|
||||
```javascript
|
||||
var noSparse = qs.parse('a[1]=b&a[15]=c');
|
||||
@@ -245,8 +270,9 @@ var withIndexedEmptyString = qs.parse('a[0]=b&a[1]=&a[2]=c');
|
||||
assert.deepEqual(withIndexedEmptyString, { a: ['b', '', 'c'] });
|
||||
```
|
||||
|
||||
**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
|
||||
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.
|
||||
**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 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.
|
||||
|
||||
```javascript
|
||||
var withMaxIndex = qs.parse('a[100]=b');
|
||||
@@ -290,7 +316,8 @@ assert.deepEqual(arraysOfObjects, { a: ['b', 'c'] })
|
||||
|
||||
### Parsing primitive/scalar values (numbers, booleans, null, etc)
|
||||
|
||||
By default, all values are parsed as strings. This behavior will not change and is explained in [issue #91](https://github.com/ljharb/qs/issues/91).
|
||||
By default, all values are parsed as strings.
|
||||
This behavior will not change and is explained in [issue #91](https://github.com/ljharb/qs/issues/91).
|
||||
|
||||
```javascript
|
||||
var primitiveValues = qs.parse('a=15&b=true&c=null');
|
||||
@@ -373,16 +400,17 @@ var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset,
|
||||
}})
|
||||
```
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
When arrays are stringified, by default they are given explicit indices:
|
||||
When arrays are stringified, they follow the `arrayFormat` option, which defaults to `indices`:
|
||||
|
||||
```javascript
|
||||
qs.stringify({ a: ['b', 'c', 'd'] });
|
||||
// 'a[0]=b&a[1]=c&a[2]=d'
|
||||
```
|
||||
|
||||
You may override this by setting the `indices` option to `false`:
|
||||
You may override this by setting the `indices` option to `false`, or to be more explicit, the `arrayFormat` option to `repeat`:
|
||||
|
||||
```javascript
|
||||
qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false });
|
||||
@@ -418,6 +446,20 @@ qs.stringify({ a: { b: { c: 'd', e: 'f' } } }, { allowDots: true });
|
||||
// 'a.b.c=d&a.b.e=f'
|
||||
```
|
||||
|
||||
You may encode the dot notation in the keys of object with option `encodeDotInKeys` by setting it to `true`:
|
||||
Note: it implies `allowDots`, so `stringify` will error if you set `decodeDotInKeys` to `true`, and `allowDots` to `false`.
|
||||
Caveat: when `encodeValuesOnly` is `true` as well as `encodeDotInKeys`, only dots in keys and nothing else will be encoded.
|
||||
```javascript
|
||||
qs.stringify({ "name.obj": { "first": "John", "last": "Doe" } }, { allowDots: true, encodeDotInKeys: true })
|
||||
// 'name%252Eobj.first=John&name%252Eobj.last=Doe'
|
||||
```
|
||||
|
||||
You may allow empty array values by setting the `allowEmptyArrays` option to `true`:
|
||||
```javascript
|
||||
qs.stringify({ foo: [], bar: 'baz' }, { allowEmptyArrays: true });
|
||||
// 'foo[]&bar=baz'
|
||||
```
|
||||
|
||||
Empty strings and null values will omit the value, but the equals sign (=) remains in place:
|
||||
|
||||
```javascript
|
||||
@@ -473,8 +515,8 @@ assert.equal(qs.stringify({ a: 'c', z: 'y', b : 'f' }, { sort: alphabeticalSort
|
||||
```
|
||||
|
||||
Finally, you can use the `filter` option to restrict which keys will be included in the stringified output.
|
||||
If you pass a function, it will be called for each key to obtain the replacement value. Otherwise, if you
|
||||
pass an array, it will be used to select properties and array indices for stringification:
|
||||
If you pass a function, it will be called for each key to obtain the replacement value.
|
||||
Otherwise, if you pass an array, it will be used to select properties and array indices for stringification:
|
||||
|
||||
```javascript
|
||||
function filterFunc(prefix, value) {
|
||||
@@ -498,6 +540,44 @@ qs.stringify({ a: ['b', 'c', 'd'], e: 'f' }, { filter: ['a', 0, 2] });
|
||||
// 'a[0]=b&a[2]=d'
|
||||
```
|
||||
|
||||
You could also use `filter` to inject custom serialization for user defined types.
|
||||
Consider you're working with some api that expects query strings of the format for ranges:
|
||||
|
||||
```
|
||||
https://domain.com/endpoint?range=30...70
|
||||
```
|
||||
|
||||
For which you model as:
|
||||
|
||||
```javascript
|
||||
class Range {
|
||||
constructor(from, to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You could _inject_ a custom serializer to handle values of this type:
|
||||
|
||||
```javascript
|
||||
qs.stringify(
|
||||
{
|
||||
range: new Range(30, 70),
|
||||
},
|
||||
{
|
||||
filter: (prefix, value) => {
|
||||
if (value instanceof Range) {
|
||||
return `${value.from}...${value.to}`;
|
||||
}
|
||||
// serialize the usual way
|
||||
return value;
|
||||
},
|
||||
}
|
||||
);
|
||||
// range=30...70
|
||||
```
|
||||
|
||||
### Handling of `null` values
|
||||
|
||||
By default, `null` values are treated like empty strings:
|
||||
@@ -507,7 +587,8 @@ var withNull = qs.stringify({ a: null, b: '' });
|
||||
assert.equal(withNull, 'a=&b=');
|
||||
```
|
||||
|
||||
Parsing does not distinguish between parameters with and without equal signs. Both are converted to empty strings.
|
||||
Parsing does not distinguish between parameters with and without equal signs.
|
||||
Both are converted to empty strings.
|
||||
|
||||
```javascript
|
||||
var equalsInsensitive = qs.parse('a&b=');
|
||||
@@ -536,25 +617,21 @@ var nullsSkipped = qs.stringify({ a: 'b', c: null}, { skipNulls: true });
|
||||
assert.equal(nullsSkipped, 'a=b');
|
||||
```
|
||||
|
||||
If you're communicating with legacy systems, you can switch to `iso-8859-1`
|
||||
using the `charset` option:
|
||||
If you're communicating with legacy systems, you can switch to `iso-8859-1` using the `charset` option:
|
||||
|
||||
```javascript
|
||||
var iso = qs.stringify({ æ: 'æ' }, { charset: 'iso-8859-1' });
|
||||
assert.equal(iso, '%E6=%E6');
|
||||
```
|
||||
|
||||
Characters that don't exist in `iso-8859-1` will be converted to numeric
|
||||
entities, similar to what browsers do:
|
||||
Characters that don't exist in `iso-8859-1` will be converted to numeric entities, similar to what browsers do:
|
||||
|
||||
```javascript
|
||||
var numeric = qs.stringify({ a: '☺' }, { charset: 'iso-8859-1' });
|
||||
assert.equal(numeric, 'a=%26%239786%3B');
|
||||
```
|
||||
|
||||
You can use the `charsetSentinel` option to announce the character by
|
||||
including an `utf8=✓` parameter with the proper encoding if the checkmark,
|
||||
similar to what Ruby on Rails and others do when submitting forms.
|
||||
You can use the `charsetSentinel` option to announce the character by including an `utf8=✓` parameter with the proper encoding if the checkmark, similar to what Ruby on Rails and others do when submitting forms.
|
||||
|
||||
```javascript
|
||||
var sentinel = qs.stringify({ a: '☺' }, { charsetSentinel: true });
|
||||
@@ -566,8 +643,7 @@ assert.equal(isoSentinel, 'utf8=%26%2310003%3B&a=%E6');
|
||||
|
||||
### Dealing with special character sets
|
||||
|
||||
By default the encoding and decoding of characters is done in `utf-8`,
|
||||
and `iso-8859-1` support is also built in via the `charset` parameter.
|
||||
By default the encoding and decoding of characters is done in `utf-8`, and `iso-8859-1` support is also built in via the `charset` parameter.
|
||||
|
||||
If you wish to encode querystrings to a different character set (i.e.
|
||||
[Shift JIS](https://en.wikipedia.org/wiki/Shift_JIS)) you can use the
|
||||
@@ -606,7 +682,9 @@ Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/se
|
||||
|
||||
Available as part of the Tidelift Subscription
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
[package-url]: https://npmjs.org/package/qs
|
||||
[npm-version-svg]: https://versionbadg.es/ljharb/qs.svg
|
||||
@@ -623,3 +701,9 @@ The maintainers of qs and thousands of other packages are working with Tidelift
|
||||
[codecov-url]: https://app.codecov.io/gh/ljharb/qs/
|
||||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/qs
|
||||
[actions-url]: https://github.com/ljharb/qs/actions
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
qs logo by [NUMI](https://github.com/numi-hq/open-design):
|
||||
|
||||
[<img src="https://raw.githubusercontent.com/numi-hq/open-design/main/assets/numi-lockup.png" alt="NUMI Logo" style="width: 200px;"/>](https://numi.tech/?ref=qs)
|
||||
|
||||
2076
node_modules/qs/dist/qs.js
generated
vendored
2076
node_modules/qs/dist/qs.js
generated
vendored
File diff suppressed because one or more lines are too long
59
node_modules/qs/lib/parse.js
generated
vendored
59
node_modules/qs/lib/parse.js
generated
vendored
@@ -7,20 +7,24 @@ var isArray = Array.isArray;
|
||||
|
||||
var defaults = {
|
||||
allowDots: false,
|
||||
allowEmptyArrays: false,
|
||||
allowPrototypes: false,
|
||||
allowSparse: false,
|
||||
arrayLimit: 20,
|
||||
charset: 'utf-8',
|
||||
charsetSentinel: false,
|
||||
comma: false,
|
||||
decodeDotInKeys: false,
|
||||
decoder: utils.decode,
|
||||
delimiter: '&',
|
||||
depth: 5,
|
||||
duplicates: 'combine',
|
||||
ignoreQueryPrefix: false,
|
||||
interpretNumericEntities: false,
|
||||
parameterLimit: 1000,
|
||||
parseArrays: true,
|
||||
plainObjects: false,
|
||||
strictDepth: false,
|
||||
strictNullHandling: false
|
||||
};
|
||||
|
||||
@@ -49,8 +53,10 @@ var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
|
||||
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
|
||||
|
||||
var parseValues = function parseQueryStringValues(str, options) {
|
||||
var obj = {};
|
||||
var obj = { __proto__: null };
|
||||
|
||||
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
||||
cleanStr = cleanStr.replace(/%5B/gi, '[').replace(/%5D/gi, ']');
|
||||
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
||||
var parts = cleanStr.split(options.delimiter, limit);
|
||||
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
|
||||
@@ -102,9 +108,10 @@ var parseValues = function parseQueryStringValues(str, options) {
|
||||
val = isArray(val) ? [val] : val;
|
||||
}
|
||||
|
||||
if (has.call(obj, key)) {
|
||||
var existing = has.call(obj, key);
|
||||
if (existing && options.duplicates === 'combine') {
|
||||
obj[key] = utils.combine(obj[key], val);
|
||||
} else {
|
||||
} else if (!existing || options.duplicates === 'last') {
|
||||
obj[key] = val;
|
||||
}
|
||||
}
|
||||
@@ -120,24 +127,27 @@ var parseObject = function (chain, val, options, valuesParsed) {
|
||||
var root = chain[i];
|
||||
|
||||
if (root === '[]' && options.parseArrays) {
|
||||
obj = [].concat(leaf);
|
||||
obj = options.allowEmptyArrays && (leaf === '' || (options.strictNullHandling && leaf === null))
|
||||
? []
|
||||
: [].concat(leaf);
|
||||
} else {
|
||||
obj = options.plainObjects ? Object.create(null) : {};
|
||||
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
||||
var index = parseInt(cleanRoot, 10);
|
||||
if (!options.parseArrays && cleanRoot === '') {
|
||||
var decodedRoot = options.decodeDotInKeys ? cleanRoot.replace(/%2E/g, '.') : cleanRoot;
|
||||
var index = parseInt(decodedRoot, 10);
|
||||
if (!options.parseArrays && decodedRoot === '') {
|
||||
obj = { 0: leaf };
|
||||
} else if (
|
||||
!isNaN(index)
|
||||
&& root !== cleanRoot
|
||||
&& String(index) === cleanRoot
|
||||
&& root !== decodedRoot
|
||||
&& String(index) === decodedRoot
|
||||
&& index >= 0
|
||||
&& (options.parseArrays && index <= options.arrayLimit)
|
||||
) {
|
||||
obj = [];
|
||||
obj[index] = leaf;
|
||||
} else if (cleanRoot !== '__proto__') {
|
||||
obj[cleanRoot] = leaf;
|
||||
} else if (decodedRoot !== '__proto__') {
|
||||
obj[decodedRoot] = leaf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,9 +202,12 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesPars
|
||||
keys.push(segment[1]);
|
||||
}
|
||||
|
||||
// If there's a remainder, just add whatever is left
|
||||
// If there's a remainder, check strictDepth option for throw, else just add whatever is left
|
||||
|
||||
if (segment) {
|
||||
if (options.strictDepth === true) {
|
||||
throw new RangeError('Input depth exceeded depth option of ' + options.depth + ' and strictDepth is true');
|
||||
}
|
||||
keys.push('[' + key.slice(segment.index) + ']');
|
||||
}
|
||||
|
||||
@@ -206,7 +219,15 @@ var normalizeParseOptions = function normalizeParseOptions(opts) {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
|
||||
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
||||
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
||||
}
|
||||
|
||||
if (typeof opts.decodeDotInKeys !== 'undefined' && typeof opts.decodeDotInKeys !== 'boolean') {
|
||||
throw new TypeError('`decodeDotInKeys` option can only be `true` or `false`, when provided');
|
||||
}
|
||||
|
||||
if (opts.decoder !== null && typeof opts.decoder !== 'undefined' && typeof opts.decoder !== 'function') {
|
||||
throw new TypeError('Decoder has to be a function.');
|
||||
}
|
||||
|
||||
@@ -215,23 +236,35 @@ var normalizeParseOptions = function normalizeParseOptions(opts) {
|
||||
}
|
||||
var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
|
||||
|
||||
var duplicates = typeof opts.duplicates === 'undefined' ? defaults.duplicates : opts.duplicates;
|
||||
|
||||
if (duplicates !== 'combine' && duplicates !== 'first' && duplicates !== 'last') {
|
||||
throw new TypeError('The duplicates option must be either combine, first, or last');
|
||||
}
|
||||
|
||||
var allowDots = typeof opts.allowDots === 'undefined' ? opts.decodeDotInKeys === true ? true : defaults.allowDots : !!opts.allowDots;
|
||||
|
||||
return {
|
||||
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
||||
allowDots: allowDots,
|
||||
allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
||||
allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
|
||||
allowSparse: typeof opts.allowSparse === 'boolean' ? opts.allowSparse : defaults.allowSparse,
|
||||
arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
|
||||
charset: charset,
|
||||
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
||||
comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
|
||||
decodeDotInKeys: typeof opts.decodeDotInKeys === 'boolean' ? opts.decodeDotInKeys : defaults.decodeDotInKeys,
|
||||
decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
|
||||
delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
|
||||
// eslint-disable-next-line no-implicit-coercion, no-extra-parens
|
||||
depth: (typeof opts.depth === 'number' || opts.depth === false) ? +opts.depth : defaults.depth,
|
||||
duplicates: duplicates,
|
||||
ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
|
||||
interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
|
||||
parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
|
||||
parseArrays: opts.parseArrays !== false,
|
||||
plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
|
||||
strictDepth: typeof opts.strictDepth === 'boolean' ? !!opts.strictDepth : defaults.strictDepth,
|
||||
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
||||
};
|
||||
};
|
||||
|
||||
81
node_modules/qs/lib/stringify.js
generated
vendored
81
node_modules/qs/lib/stringify.js
generated
vendored
@@ -19,7 +19,6 @@ var arrayPrefixGenerators = {
|
||||
};
|
||||
|
||||
var isArray = Array.isArray;
|
||||
var split = String.prototype.split;
|
||||
var push = Array.prototype.push;
|
||||
var pushToArray = function (arr, valueOrArray) {
|
||||
push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
||||
@@ -31,10 +30,13 @@ var defaultFormat = formats['default'];
|
||||
var defaults = {
|
||||
addQueryPrefix: false,
|
||||
allowDots: false,
|
||||
allowEmptyArrays: false,
|
||||
arrayFormat: 'indices',
|
||||
charset: 'utf-8',
|
||||
charsetSentinel: false,
|
||||
delimiter: '&',
|
||||
encode: true,
|
||||
encodeDotInKeys: false,
|
||||
encoder: utils.encode,
|
||||
encodeValuesOnly: false,
|
||||
format: defaultFormat,
|
||||
@@ -63,8 +65,10 @@ var stringify = function stringify(
|
||||
prefix,
|
||||
generateArrayPrefix,
|
||||
commaRoundTrip,
|
||||
allowEmptyArrays,
|
||||
strictNullHandling,
|
||||
skipNulls,
|
||||
encodeDotInKeys,
|
||||
encoder,
|
||||
filter,
|
||||
sort,
|
||||
@@ -121,14 +125,6 @@ var stringify = function stringify(
|
||||
if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
|
||||
if (encoder) {
|
||||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format);
|
||||
if (generateArrayPrefix === 'comma' && encodeValuesOnly) {
|
||||
var valuesArray = split.call(String(obj), ',');
|
||||
var valuesJoined = '';
|
||||
for (var i = 0; i < valuesArray.length; ++i) {
|
||||
valuesJoined += (i === 0 ? '' : ',') + formatter(encoder(valuesArray[i], defaults.encoder, charset, 'value', format));
|
||||
}
|
||||
return [formatter(keyValue) + (commaRoundTrip && isArray(obj) && valuesArray.length === 1 ? '[]' : '') + '=' + valuesJoined];
|
||||
}
|
||||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))];
|
||||
}
|
||||
return [formatter(prefix) + '=' + formatter(String(obj))];
|
||||
@@ -143,6 +139,9 @@ var stringify = function stringify(
|
||||
var objKeys;
|
||||
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
||||
// we need to join elements in
|
||||
if (encodeValuesOnly && encoder) {
|
||||
obj = utils.maybeMap(obj, encoder);
|
||||
}
|
||||
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
||||
} else if (isArray(filter)) {
|
||||
objKeys = filter;
|
||||
@@ -151,7 +150,13 @@ var stringify = function stringify(
|
||||
objKeys = sort ? keys.sort(sort) : keys;
|
||||
}
|
||||
|
||||
var adjustedPrefix = commaRoundTrip && isArray(obj) && obj.length === 1 ? prefix + '[]' : prefix;
|
||||
var encodedPrefix = encodeDotInKeys ? prefix.replace(/\./g, '%2E') : prefix;
|
||||
|
||||
var adjustedPrefix = commaRoundTrip && isArray(obj) && obj.length === 1 ? encodedPrefix + '[]' : encodedPrefix;
|
||||
|
||||
if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
|
||||
return adjustedPrefix + '[]';
|
||||
}
|
||||
|
||||
for (var j = 0; j < objKeys.length; ++j) {
|
||||
var key = objKeys[j];
|
||||
@@ -161,9 +166,10 @@ var stringify = function stringify(
|
||||
continue;
|
||||
}
|
||||
|
||||
var encodedKey = allowDots && encodeDotInKeys ? key.replace(/\./g, '%2E') : key;
|
||||
var keyPrefix = isArray(obj)
|
||||
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, key) : adjustedPrefix
|
||||
: adjustedPrefix + (allowDots ? '.' + key : '[' + key + ']');
|
||||
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, encodedKey) : adjustedPrefix
|
||||
: adjustedPrefix + (allowDots ? '.' + encodedKey : '[' + encodedKey + ']');
|
||||
|
||||
sideChannel.set(object, step);
|
||||
var valueSideChannel = getSideChannel();
|
||||
@@ -173,9 +179,11 @@ var stringify = function stringify(
|
||||
keyPrefix,
|
||||
generateArrayPrefix,
|
||||
commaRoundTrip,
|
||||
allowEmptyArrays,
|
||||
strictNullHandling,
|
||||
skipNulls,
|
||||
encoder,
|
||||
encodeDotInKeys,
|
||||
generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder,
|
||||
filter,
|
||||
sort,
|
||||
allowDots,
|
||||
@@ -196,6 +204,14 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
||||
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
||||
}
|
||||
|
||||
if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
|
||||
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
|
||||
}
|
||||
|
||||
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
|
||||
throw new TypeError('Encoder has to be a function.');
|
||||
}
|
||||
@@ -219,13 +235,32 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
|
||||
filter = opts.filter;
|
||||
}
|
||||
|
||||
var arrayFormat;
|
||||
if (opts.arrayFormat in arrayPrefixGenerators) {
|
||||
arrayFormat = opts.arrayFormat;
|
||||
} else if ('indices' in opts) {
|
||||
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
||||
} else {
|
||||
arrayFormat = defaults.arrayFormat;
|
||||
}
|
||||
|
||||
if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
||||
throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
|
||||
}
|
||||
|
||||
var allowDots = typeof opts.allowDots === 'undefined' ? opts.encodeDotInKeys === true ? true : defaults.allowDots : !!opts.allowDots;
|
||||
|
||||
return {
|
||||
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
||||
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
||||
allowDots: allowDots,
|
||||
allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
||||
arrayFormat: arrayFormat,
|
||||
charset: charset,
|
||||
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
||||
commaRoundTrip: opts.commaRoundTrip,
|
||||
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
||||
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
||||
encodeDotInKeys: typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
|
||||
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
||||
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
||||
filter: filter,
|
||||
@@ -259,20 +294,8 @@ module.exports = function (object, opts) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var arrayFormat;
|
||||
if (opts && opts.arrayFormat in arrayPrefixGenerators) {
|
||||
arrayFormat = opts.arrayFormat;
|
||||
} else if (opts && 'indices' in opts) {
|
||||
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
||||
} else {
|
||||
arrayFormat = 'indices';
|
||||
}
|
||||
|
||||
var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
|
||||
if (opts && 'commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
||||
throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
|
||||
}
|
||||
var commaRoundTrip = generateArrayPrefix === 'comma' && opts && opts.commaRoundTrip;
|
||||
var generateArrayPrefix = arrayPrefixGenerators[options.arrayFormat];
|
||||
var commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;
|
||||
|
||||
if (!objKeys) {
|
||||
objKeys = Object.keys(obj);
|
||||
@@ -294,8 +317,10 @@ module.exports = function (object, opts) {
|
||||
key,
|
||||
generateArrayPrefix,
|
||||
commaRoundTrip,
|
||||
options.allowEmptyArrays,
|
||||
options.strictNullHandling,
|
||||
options.skipNulls,
|
||||
options.encodeDotInKeys,
|
||||
options.encode ? options.encoder : null,
|
||||
options.filter,
|
||||
options.sort,
|
||||
|
||||
85
node_modules/qs/lib/utils.js
generated
vendored
85
node_modules/qs/lib/utils.js
generated
vendored
@@ -122,6 +122,10 @@ var decode = function (str, decoder, charset) {
|
||||
}
|
||||
};
|
||||
|
||||
var limit = 1024;
|
||||
|
||||
/* eslint operator-linebreak: [2, "before"] */
|
||||
|
||||
var encode = function encode(str, defaultEncoder, charset, kind, format) {
|
||||
// This code was originally written by Brian White (mscdex) for the io.js core querystring library.
|
||||
// It has been adapted here for stricter adherence to RFC 3986
|
||||
@@ -143,45 +147,54 @@ var encode = function encode(str, defaultEncoder, charset, kind, format) {
|
||||
}
|
||||
|
||||
var out = '';
|
||||
for (var i = 0; i < string.length; ++i) {
|
||||
var c = string.charCodeAt(i);
|
||||
for (var j = 0; j < string.length; j += limit) {
|
||||
var segment = string.length >= limit ? string.slice(j, j + limit) : string;
|
||||
var arr = [];
|
||||
|
||||
if (
|
||||
c === 0x2D // -
|
||||
|| c === 0x2E // .
|
||||
|| c === 0x5F // _
|
||||
|| c === 0x7E // ~
|
||||
|| (c >= 0x30 && c <= 0x39) // 0-9
|
||||
|| (c >= 0x41 && c <= 0x5A) // a-z
|
||||
|| (c >= 0x61 && c <= 0x7A) // A-Z
|
||||
|| (format === formats.RFC1738 && (c === 0x28 || c === 0x29)) // ( )
|
||||
) {
|
||||
out += string.charAt(i);
|
||||
continue;
|
||||
for (var i = 0; i < segment.length; ++i) {
|
||||
var c = segment.charCodeAt(i);
|
||||
if (
|
||||
c === 0x2D // -
|
||||
|| c === 0x2E // .
|
||||
|| c === 0x5F // _
|
||||
|| c === 0x7E // ~
|
||||
|| (c >= 0x30 && c <= 0x39) // 0-9
|
||||
|| (c >= 0x41 && c <= 0x5A) // a-z
|
||||
|| (c >= 0x61 && c <= 0x7A) // A-Z
|
||||
|| (format === formats.RFC1738 && (c === 0x28 || c === 0x29)) // ( )
|
||||
) {
|
||||
arr[arr.length] = segment.charAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c < 0x80) {
|
||||
arr[arr.length] = hexTable[c];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c < 0x800) {
|
||||
arr[arr.length] = hexTable[0xC0 | (c >> 6)]
|
||||
+ hexTable[0x80 | (c & 0x3F)];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c < 0xD800 || c >= 0xE000) {
|
||||
arr[arr.length] = hexTable[0xE0 | (c >> 12)]
|
||||
+ hexTable[0x80 | ((c >> 6) & 0x3F)]
|
||||
+ hexTable[0x80 | (c & 0x3F)];
|
||||
continue;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
c = 0x10000 + (((c & 0x3FF) << 10) | (segment.charCodeAt(i) & 0x3FF));
|
||||
|
||||
arr[arr.length] = hexTable[0xF0 | (c >> 18)]
|
||||
+ hexTable[0x80 | ((c >> 12) & 0x3F)]
|
||||
+ hexTable[0x80 | ((c >> 6) & 0x3F)]
|
||||
+ hexTable[0x80 | (c & 0x3F)];
|
||||
}
|
||||
|
||||
if (c < 0x80) {
|
||||
out = out + hexTable[c];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c < 0x800) {
|
||||
out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c < 0xD800 || c >= 0xE000) {
|
||||
out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
|
||||
continue;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
|
||||
/* eslint operator-linebreak: [2, "before"] */
|
||||
out += hexTable[0xF0 | (c >> 18)]
|
||||
+ hexTable[0x80 | ((c >> 12) & 0x3F)]
|
||||
+ hexTable[0x80 | ((c >> 6) & 0x3F)]
|
||||
+ hexTable[0x80 | (c & 0x3F)];
|
||||
out += arr.join('');
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
38
node_modules/qs/package.json
generated
vendored
38
node_modules/qs/package.json
generated
vendored
@@ -2,7 +2,7 @@
|
||||
"name": "qs",
|
||||
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
|
||||
"homepage": "https://github.com/ljharb/qs",
|
||||
"version": "6.11.0",
|
||||
"version": "6.13.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ljharb/qs.git"
|
||||
@@ -11,6 +11,7 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"sideEffects": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Jordan Harband",
|
||||
@@ -30,40 +31,51 @@
|
||||
"node": ">=0.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"side-channel": "^1.0.4"
|
||||
"side-channel": "^1.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ljharb/eslint-config": "^21.0.0",
|
||||
"aud": "^2.0.0",
|
||||
"@browserify/envify": "^6.0.0",
|
||||
"@browserify/uglifyify": "^6.0.0",
|
||||
"@ljharb/eslint-config": "^21.1.1",
|
||||
"browserify": "^16.5.2",
|
||||
"bundle-collapser": "^1.4.0",
|
||||
"common-shakeify": "~1.0.0",
|
||||
"eclint": "^2.8.1",
|
||||
"es-value-fixtures": "^1.4.2",
|
||||
"eslint": "=8.8.0",
|
||||
"evalmd": "^0.0.19",
|
||||
"for-each": "^0.3.3",
|
||||
"glob": "=10.3.7",
|
||||
"has-override-mistake": "^1.0.1",
|
||||
"has-property-descriptors": "^1.0.2",
|
||||
"has-symbols": "^1.0.3",
|
||||
"iconv-lite": "^0.5.1",
|
||||
"in-publish": "^2.0.1",
|
||||
"jackspeak": "=2.1.1",
|
||||
"mkdirp": "^0.5.5",
|
||||
"npmignore": "^0.3.0",
|
||||
"mock-property": "^1.0.3",
|
||||
"module-deps": "^6.2.3",
|
||||
"npmignore": "^0.3.1",
|
||||
"nyc": "^10.3.2",
|
||||
"object-inspect": "^1.12.2",
|
||||
"object-inspect": "^1.13.2",
|
||||
"qs-iconv": "^1.0.4",
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"safer-buffer": "^2.1.2",
|
||||
"tape": "^5.5.3"
|
||||
"tape": "^5.8.1",
|
||||
"unassertify": "^3.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"prepack": "npmignore --auto --commentLines=autogenerated",
|
||||
"prepublishOnly": "safe-publish-latest && npm run dist",
|
||||
"prepack": "npmignore --auto --commentLines=autogenerated && npm run dist",
|
||||
"prepublishOnly": "safe-publish-latest",
|
||||
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||
"pretest": "npm run --silent readme && npm run --silent lint",
|
||||
"test": "npm run tests-only",
|
||||
"tests-only": "nyc tape 'test/**/*.js'",
|
||||
"posttest": "aud --production",
|
||||
"posttest": "npx npm@'>=10.2' audit --production",
|
||||
"readme": "evalmd README.md",
|
||||
"postlint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git' | grep -v dist/)",
|
||||
"lint": "eslint --ext=js,mjs .",
|
||||
"dist": "mkdirp dist && browserify --standalone Qs lib/index.js > dist/qs.js"
|
||||
"dist": "mkdirp dist && browserify --standalone Qs -g unassertify -g @browserify/envify -g [@browserify/uglifyify --mangle.keep_fnames --compress.keep_fnames --format.indent_level=1 --compress.arrows=false --compress.passes=4 --compress.typeofs=false] -p common-shakeify -p bundle-collapser/plugin lib/index.js > dist/qs.js"
|
||||
},
|
||||
"license": "BSD-3-Clause",
|
||||
"publishConfig": {
|
||||
@@ -71,7 +83,9 @@
|
||||
"!dist/*",
|
||||
"bower.json",
|
||||
"component.json",
|
||||
".github/workflows"
|
||||
".github/workflows",
|
||||
"logos",
|
||||
"tea.yaml"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
385
node_modules/qs/test/parse.js
generated
vendored
385
node_modules/qs/test/parse.js
generated
vendored
@@ -1,10 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var hasPropertyDescriptors = require('has-property-descriptors')();
|
||||
var iconv = require('iconv-lite');
|
||||
var mockProperty = require('mock-property');
|
||||
var hasOverrideMistake = require('has-override-mistake')();
|
||||
var SaferBuffer = require('safer-buffer').Buffer;
|
||||
var v = require('es-value-fixtures');
|
||||
var inspect = require('object-inspect');
|
||||
var emptyTestCases = require('./empty-keys-cases').emptyTestCases;
|
||||
|
||||
var qs = require('../');
|
||||
var utils = require('../lib/utils');
|
||||
var iconv = require('iconv-lite');
|
||||
var SaferBuffer = require('safer-buffer').Buffer;
|
||||
|
||||
test('parse()', function (t) {
|
||||
t.test('parses a simple string', function (st) {
|
||||
@@ -32,41 +39,156 @@ test('parse()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('arrayFormat: brackets allows only explicit arrays', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'brackets' }), { a: 'b,c' });
|
||||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
|
||||
t.test('comma: false', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c'), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c'), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c'), { a: 'b,c' });
|
||||
st.deepEqual(qs.parse('a=b&a=c'), { a: ['b', 'c'] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('arrayFormat: indices allows only indexed arrays', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'indices' }), { a: 'b,c' });
|
||||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('arrayFormat: comma allows only comma-separated arrays', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'comma' }), { a: 'b,c' });
|
||||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('arrayFormat: repeat allows only repeated values', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'repeat' }), { a: 'b,c' });
|
||||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
|
||||
t.test('comma: true', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c', { comma: true }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { comma: true }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c', { comma: true }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b&a=c', { comma: true }), { a: ['b', 'c'] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('allows enabling dot notation', function (st) {
|
||||
st.deepEqual(qs.parse('a.b=c'), { 'a.b': 'c' });
|
||||
st.deepEqual(qs.parse('a.b=c', { allowDots: true }), { a: { b: 'c' } });
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('decode dot keys correctly', function (st) {
|
||||
st.deepEqual(
|
||||
qs.parse('name%252Eobj.first=John&name%252Eobj.last=Doe', { allowDots: false, decodeDotInKeys: false }),
|
||||
{ 'name%2Eobj.first': 'John', 'name%2Eobj.last': 'Doe' },
|
||||
'with allowDots false and decodeDotInKeys false'
|
||||
);
|
||||
st.deepEqual(
|
||||
qs.parse('name.obj.first=John&name.obj.last=Doe', { allowDots: true, decodeDotInKeys: false }),
|
||||
{ name: { obj: { first: 'John', last: 'Doe' } } },
|
||||
'with allowDots false and decodeDotInKeys false'
|
||||
);
|
||||
st.deepEqual(
|
||||
qs.parse('name%252Eobj.first=John&name%252Eobj.last=Doe', { allowDots: true, decodeDotInKeys: false }),
|
||||
{ 'name%2Eobj': { first: 'John', last: 'Doe' } },
|
||||
'with allowDots true and decodeDotInKeys false'
|
||||
);
|
||||
st.deepEqual(
|
||||
qs.parse('name%252Eobj.first=John&name%252Eobj.last=Doe', { allowDots: true, decodeDotInKeys: true }),
|
||||
{ 'name.obj': { first: 'John', last: 'Doe' } },
|
||||
'with allowDots true and decodeDotInKeys true'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
qs.parse(
|
||||
'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',
|
||||
{ allowDots: false, decodeDotInKeys: false }
|
||||
),
|
||||
{ 'name%2Eobj%2Esubobject.first%2Egodly%2Ename': 'John', 'name%2Eobj%2Esubobject.last': 'Doe' },
|
||||
'with allowDots false and decodeDotInKeys false'
|
||||
);
|
||||
st.deepEqual(
|
||||
qs.parse(
|
||||
'name.obj.subobject.first.godly.name=John&name.obj.subobject.last=Doe',
|
||||
{ allowDots: true, decodeDotInKeys: false }
|
||||
),
|
||||
{ name: { obj: { subobject: { first: { godly: { name: 'John' } }, last: 'Doe' } } } },
|
||||
'with allowDots true and decodeDotInKeys false'
|
||||
);
|
||||
st.deepEqual(
|
||||
qs.parse(
|
||||
'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',
|
||||
{ allowDots: true, decodeDotInKeys: true }
|
||||
),
|
||||
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
||||
'with allowDots true and decodeDotInKeys true'
|
||||
);
|
||||
st.deepEqual(
|
||||
qs.parse('name%252Eobj.first=John&name%252Eobj.last=Doe'),
|
||||
{ 'name%2Eobj.first': 'John', 'name%2Eobj.last': 'Doe' },
|
||||
'with allowDots and decodeDotInKeys undefined'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('should decode dot in key of object, and allow enabling dot notation when decodeDotInKeys is set to true and allowDots is undefined', function (st) {
|
||||
st.deepEqual(
|
||||
qs.parse(
|
||||
'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',
|
||||
{ decodeDotInKeys: true }
|
||||
),
|
||||
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
||||
'with allowDots undefined and decodeDotInKeys true'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('should throw when decodeDotInKeys is not of type boolean', function (st) {
|
||||
st['throws'](
|
||||
function () { qs.parse('foo[]&bar=baz', { decodeDotInKeys: 'foobar' }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.parse('foo[]&bar=baz', { decodeDotInKeys: 0 }); },
|
||||
TypeError
|
||||
);
|
||||
st['throws'](
|
||||
function () { qs.parse('foo[]&bar=baz', { decodeDotInKeys: NaN }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.parse('foo[]&bar=baz', { decodeDotInKeys: null }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('allows empty arrays in obj values', function (st) {
|
||||
st.deepEqual(qs.parse('foo[]&bar=baz', { allowEmptyArrays: true }), { foo: [], bar: 'baz' });
|
||||
st.deepEqual(qs.parse('foo[]&bar=baz', { allowEmptyArrays: false }), { foo: [''], bar: 'baz' });
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('should throw when allowEmptyArrays is not of type boolean', function (st) {
|
||||
st['throws'](
|
||||
function () { qs.parse('foo[]&bar=baz', { allowEmptyArrays: 'foobar' }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.parse('foo[]&bar=baz', { allowEmptyArrays: 0 }); },
|
||||
TypeError
|
||||
);
|
||||
st['throws'](
|
||||
function () { qs.parse('foo[]&bar=baz', { allowEmptyArrays: NaN }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.parse('foo[]&bar=baz', { allowEmptyArrays: null }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('allowEmptyArrays + strictNullHandling', function (st) {
|
||||
st.deepEqual(
|
||||
qs.parse('testEmptyArray[]', { strictNullHandling: true, allowEmptyArrays: true }),
|
||||
{ testEmptyArray: [] }
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -322,14 +444,14 @@ test('parse()', function (t) {
|
||||
});
|
||||
|
||||
t.test('should not throw when a native prototype has an enumerable property', function (st) {
|
||||
Object.prototype.crash = '';
|
||||
Array.prototype.crash = '';
|
||||
st.intercept(Object.prototype, 'crash', { value: '' });
|
||||
st.intercept(Array.prototype, 'crash', { value: '' });
|
||||
|
||||
st.doesNotThrow(qs.parse.bind(null, 'a=b'));
|
||||
st.deepEqual(qs.parse('a=b'), { a: 'b' });
|
||||
st.doesNotThrow(qs.parse.bind(null, 'a[][b]=c'));
|
||||
st.deepEqual(qs.parse('a[][b]=c'), { a: [{ b: 'c' }] });
|
||||
delete Object.prototype.crash;
|
||||
delete Array.prototype.crash;
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -360,8 +482,14 @@ test('parse()', function (t) {
|
||||
|
||||
t.test('allows overriding array limit', function (st) {
|
||||
st.deepEqual(qs.parse('a[0]=b', { arrayLimit: -1 }), { a: { 0: 'b' } });
|
||||
st.deepEqual(qs.parse('a[0]=b', { arrayLimit: 0 }), { a: ['b'] });
|
||||
|
||||
st.deepEqual(qs.parse('a[-1]=b', { arrayLimit: -1 }), { a: { '-1': 'b' } });
|
||||
st.deepEqual(qs.parse('a[-1]=b', { arrayLimit: 0 }), { a: { '-1': 'b' } });
|
||||
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayLimit: -1 }), { a: { 0: 'b', 1: 'c' } });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayLimit: 0 }), { a: { 0: 'b', 1: 'c' } });
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -452,6 +580,15 @@ test('parse()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('parses url-encoded brackets holds array of arrays when having two parts of strings with comma as array divider', function (st) {
|
||||
st.deepEqual(qs.parse('foo%5B%5D=1,2,3&foo%5B%5D=4,5,6', { comma: true }), { foo: [['1', '2', '3'], ['4', '5', '6']] });
|
||||
st.deepEqual(qs.parse('foo%5B%5D=1,2,3&foo%5B%5D=', { comma: true }), { foo: [['1', '2', '3'], ''] });
|
||||
st.deepEqual(qs.parse('foo%5B%5D=1,2,3&foo%5B%5D=,', { comma: true }), { foo: [['1', '2', '3'], ['', '']] });
|
||||
st.deepEqual(qs.parse('foo%5B%5D=1,2,3&foo%5B%5D=a', { comma: true }), { foo: [['1', '2', '3'], 'a'] });
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('parses comma delimited array while having percent-encoded comma treated as normal text', function (st) {
|
||||
st.deepEqual(qs.parse('foo=a%2Cb', { comma: true }), { foo: 'a,b' });
|
||||
st.deepEqual(qs.parse('foo=a%2C%20b,d', { comma: true }), { foo: ['a, b', 'd'] });
|
||||
@@ -499,10 +636,12 @@ test('parse()', function (t) {
|
||||
});
|
||||
|
||||
t.test('does not blow up when Buffer global is missing', function (st) {
|
||||
var tempBuffer = global.Buffer;
|
||||
delete global.Buffer;
|
||||
var restore = mockProperty(global, 'Buffer', { 'delete': true });
|
||||
|
||||
var result = qs.parse('a=b&c=d');
|
||||
global.Buffer = tempBuffer;
|
||||
|
||||
restore();
|
||||
|
||||
st.deepEqual(result, { a: 'b', c: 'd' });
|
||||
st.end();
|
||||
});
|
||||
@@ -601,6 +740,34 @@ test('parse()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('does not crash when the global Object prototype is frozen', { skip: !hasPropertyDescriptors || !hasOverrideMistake }, function (st) {
|
||||
// We can't actually freeze the global Object prototype as that will interfere with other tests, and once an object is frozen, it
|
||||
// can't be unfrozen. Instead, we add a new non-writable property to simulate this.
|
||||
st.teardown(mockProperty(Object.prototype, 'frozenProp', { value: 'foo', nonWritable: true, nonEnumerable: true }));
|
||||
|
||||
st['throws'](
|
||||
function () {
|
||||
var obj = {};
|
||||
obj.frozenProp = 'bar';
|
||||
},
|
||||
// node < 6 has a different error message
|
||||
/^TypeError: Cannot assign to read only property 'frozenProp' of (?:object '#<Object>'|#<Object>)/,
|
||||
'regular assignment of an inherited non-writable property throws'
|
||||
);
|
||||
|
||||
var parsed;
|
||||
st.doesNotThrow(
|
||||
function () {
|
||||
parsed = qs.parse('frozenProp', { allowPrototypes: false });
|
||||
},
|
||||
'parsing a nonwritable Object.prototype property does not throw'
|
||||
);
|
||||
|
||||
st.deepEqual(parsed, {}, 'bare "frozenProp" results in {}');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('params starting with a closing bracket', function (st) {
|
||||
st.deepEqual(qs.parse(']=toString'), { ']': 'toString' });
|
||||
st.deepEqual(qs.parse(']]=toString'), { ']]': 'toString' });
|
||||
@@ -853,3 +1020,151 @@ test('parse()', function (t) {
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('parses empty keys', function (t) {
|
||||
emptyTestCases.forEach(function (testCase) {
|
||||
t.test('skips empty string key with ' + testCase.input, function (st) {
|
||||
st.deepEqual(qs.parse(testCase.input), testCase.noEmptyKeys);
|
||||
|
||||
st.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('`duplicates` option', function (t) {
|
||||
v.nonStrings.concat('not a valid option').forEach(function (invalidOption) {
|
||||
if (typeof invalidOption !== 'undefined') {
|
||||
t['throws'](
|
||||
function () { qs.parse('', { duplicates: invalidOption }); },
|
||||
TypeError,
|
||||
'throws on invalid option: ' + inspect(invalidOption)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
t.deepEqual(
|
||||
qs.parse('foo=bar&foo=baz'),
|
||||
{ foo: ['bar', 'baz'] },
|
||||
'duplicates: default, combine'
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
qs.parse('foo=bar&foo=baz', { duplicates: 'combine' }),
|
||||
{ foo: ['bar', 'baz'] },
|
||||
'duplicates: combine'
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
qs.parse('foo=bar&foo=baz', { duplicates: 'first' }),
|
||||
{ foo: 'bar' },
|
||||
'duplicates: first'
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
qs.parse('foo=bar&foo=baz', { duplicates: 'last' }),
|
||||
{ foo: 'baz' },
|
||||
'duplicates: last'
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('qs strictDepth option - throw cases', function (t) {
|
||||
t.test('throws an exception when depth exceeds the limit with strictDepth: true', function (st) {
|
||||
st['throws'](
|
||||
function () {
|
||||
qs.parse('a[b][c][d][e][f][g][h][i]=j', { depth: 1, strictDepth: true });
|
||||
},
|
||||
RangeError,
|
||||
'Should throw RangeError'
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('throws an exception for multiple nested arrays with strictDepth: true', function (st) {
|
||||
st['throws'](
|
||||
function () {
|
||||
qs.parse('a[0][1][2][3][4]=b', { depth: 3, strictDepth: true });
|
||||
},
|
||||
RangeError,
|
||||
'Should throw RangeError'
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('throws an exception for nested objects and arrays with strictDepth: true', function (st) {
|
||||
st['throws'](
|
||||
function () {
|
||||
qs.parse('a[b][c][0][d][e]=f', { depth: 3, strictDepth: true });
|
||||
},
|
||||
RangeError,
|
||||
'Should throw RangeError'
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('throws an exception for different types of values with strictDepth: true', function (st) {
|
||||
st['throws'](
|
||||
function () {
|
||||
qs.parse('a[b][c][d][e]=true&a[b][c][d][f]=42', { depth: 3, strictDepth: true });
|
||||
},
|
||||
RangeError,
|
||||
'Should throw RangeError'
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('qs strictDepth option - non-throw cases', function (t) {
|
||||
t.test('when depth is 0 and strictDepth true, do not throw', function (st) {
|
||||
st.doesNotThrow(
|
||||
function () {
|
||||
qs.parse('a[b][c][d][e]=true&a[b][c][d][f]=42', { depth: 0, strictDepth: true });
|
||||
},
|
||||
RangeError,
|
||||
'Should not throw RangeError'
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('parses successfully when depth is within the limit with strictDepth: true', function (st) {
|
||||
st.doesNotThrow(
|
||||
function () {
|
||||
var result = qs.parse('a[b]=c', { depth: 1, strictDepth: true });
|
||||
st.deepEqual(result, { a: { b: 'c' } }, 'Should parse correctly');
|
||||
}
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('does not throw an exception when depth exceeds the limit with strictDepth: false', function (st) {
|
||||
st.doesNotThrow(
|
||||
function () {
|
||||
var result = qs.parse('a[b][c][d][e][f][g][h][i]=j', { depth: 1 });
|
||||
st.deepEqual(result, { a: { b: { '[c][d][e][f][g][h][i]': 'j' } } }, 'Should parse with depth limit');
|
||||
}
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('parses successfully when depth is within the limit with strictDepth: false', function (st) {
|
||||
st.doesNotThrow(
|
||||
function () {
|
||||
var result = qs.parse('a[b]=c', { depth: 1 });
|
||||
st.deepEqual(result, { a: { b: 'c' } }, 'Should parse correctly');
|
||||
}
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('does not throw when depth is exactly at the limit with strictDepth: true', function (st) {
|
||||
st.doesNotThrow(
|
||||
function () {
|
||||
var result = qs.parse('a[b][c]=d', { depth: 2, strictDepth: true });
|
||||
st.deepEqual(result, { a: { b: { c: 'd' } } }, 'Should parse correctly');
|
||||
}
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
});
|
||||
|
||||
483
node_modules/qs/test/stringify.js
generated
vendored
483
node_modules/qs/test/stringify.js
generated
vendored
@@ -6,6 +6,8 @@ var utils = require('../lib/utils');
|
||||
var iconv = require('iconv-lite');
|
||||
var SaferBuffer = require('safer-buffer').Buffer;
|
||||
var hasSymbols = require('has-symbols');
|
||||
var mockProperty = require('mock-property');
|
||||
var emptyTestCases = require('./empty-keys-cases').emptyTestCases;
|
||||
var hasBigInt = typeof BigInt === 'function';
|
||||
|
||||
test('stringify()', function (t) {
|
||||
@@ -63,6 +65,138 @@ test('stringify()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('encodes dot in key of object when encodeDotInKeys and allowDots is provided', function (st) {
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ 'name.obj': { first: 'John', last: 'Doe' } },
|
||||
{ allowDots: false, encodeDotInKeys: false }
|
||||
),
|
||||
'name.obj%5Bfirst%5D=John&name.obj%5Blast%5D=Doe',
|
||||
'with allowDots false and encodeDotInKeys false'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ 'name.obj': { first: 'John', last: 'Doe' } },
|
||||
{ allowDots: true, encodeDotInKeys: false }
|
||||
),
|
||||
'name.obj.first=John&name.obj.last=Doe',
|
||||
'with allowDots true and encodeDotInKeys false'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ 'name.obj': { first: 'John', last: 'Doe' } },
|
||||
{ allowDots: false, encodeDotInKeys: true }
|
||||
),
|
||||
'name%252Eobj%5Bfirst%5D=John&name%252Eobj%5Blast%5D=Doe',
|
||||
'with allowDots false and encodeDotInKeys true'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ 'name.obj': { first: 'John', last: 'Doe' } },
|
||||
{ allowDots: true, encodeDotInKeys: true }
|
||||
),
|
||||
'name%252Eobj.first=John&name%252Eobj.last=Doe',
|
||||
'with allowDots true and encodeDotInKeys true'
|
||||
);
|
||||
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
||||
{ allowDots: false, encodeDotInKeys: false }
|
||||
),
|
||||
'name.obj.subobject%5Bfirst.godly.name%5D=John&name.obj.subobject%5Blast%5D=Doe',
|
||||
'with allowDots false and encodeDotInKeys false'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
||||
{ allowDots: true, encodeDotInKeys: false }
|
||||
),
|
||||
'name.obj.subobject.first.godly.name=John&name.obj.subobject.last=Doe',
|
||||
'with allowDots false and encodeDotInKeys false'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
||||
{ allowDots: false, encodeDotInKeys: true }
|
||||
),
|
||||
'name%252Eobj%252Esubobject%5Bfirst.godly.name%5D=John&name%252Eobj%252Esubobject%5Blast%5D=Doe',
|
||||
'with allowDots false and encodeDotInKeys true'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
||||
{ allowDots: true, encodeDotInKeys: true }
|
||||
),
|
||||
'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',
|
||||
'with allowDots true and encodeDotInKeys true'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('should encode dot in key of object, and automatically set allowDots to `true` when encodeDotInKeys is true and allowDots in undefined', function (st) {
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
||||
{ encodeDotInKeys: true }
|
||||
),
|
||||
'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',
|
||||
'with allowDots undefined and encodeDotInKeys true'
|
||||
);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('should encode dot in key of object when encodeDotInKeys and allowDots is provided, and nothing else when encodeValuesOnly is provided', function (st) {
|
||||
st.equal(
|
||||
qs.stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, {
|
||||
encodeDotInKeys: true, allowDots: true, encodeValuesOnly: true
|
||||
}),
|
||||
'name%2Eobj.first=John&name%2Eobj.last=Doe'
|
||||
);
|
||||
|
||||
st.equal(
|
||||
qs.stringify({ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } }, { allowDots: true, encodeDotInKeys: true, encodeValuesOnly: true }),
|
||||
'name%2Eobj%2Esubobject.first%2Egodly%2Ename=John&name%2Eobj%2Esubobject.last=Doe'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('throws when `commaRoundTrip` is not a boolean', function (st) {
|
||||
st['throws'](
|
||||
function () { qs.stringify({}, { commaRoundTrip: 'not a boolean' }); },
|
||||
TypeError,
|
||||
'throws when `commaRoundTrip` is not a boolean'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('throws when `encodeDotInKeys` is not a boolean', function (st) {
|
||||
st['throws'](
|
||||
function () { qs.stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 'foobar' }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 0 }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.stringify({ a: [], b: 'zz' }, { encodeDotInKeys: NaN }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.stringify({ a: [], b: 'zz' }, { encodeDotInKeys: null }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('adds query prefix', function (st) {
|
||||
st.equal(qs.stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b');
|
||||
st.end();
|
||||
@@ -86,7 +220,7 @@ test('stringify()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('stringifies a nested object with dots notation', function (st) {
|
||||
t.test('`allowDots` option: stringifies a nested object with dots notation', function (st) {
|
||||
st.equal(qs.stringify({ a: { b: 'c' } }, { allowDots: true }), 'a.b=c');
|
||||
st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }, { allowDots: true }), 'a.b.c.d=e');
|
||||
st.end();
|
||||
@@ -108,6 +242,11 @@ test('stringify()', function (t) {
|
||||
'a=b%2Cc%2Cd',
|
||||
'comma => comma'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma', commaRoundTrip: true }),
|
||||
'a=b%2Cc%2Cd',
|
||||
'comma round trip => comma'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify({ a: ['b', 'c', 'd'] }),
|
||||
'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',
|
||||
@@ -116,18 +255,75 @@ test('stringify()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('omits nulls when asked', function (st) {
|
||||
st.equal(qs.stringify({ a: 'b', c: null }, { skipNulls: true }), 'a=b');
|
||||
st.end();
|
||||
});
|
||||
t.test('`skipNulls` option', function (st) {
|
||||
st.equal(
|
||||
qs.stringify({ a: 'b', c: null }, { skipNulls: true }),
|
||||
'a=b',
|
||||
'omits nulls when asked'
|
||||
);
|
||||
|
||||
st.equal(
|
||||
qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true }),
|
||||
'a%5Bb%5D=c',
|
||||
'omits nested nulls when asked'
|
||||
);
|
||||
|
||||
t.test('omits nested nulls when asked', function (st) {
|
||||
st.equal(qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true }), 'a%5Bb%5D=c');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('omits array indices when asked', function (st) {
|
||||
st.equal(qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false }), 'a=b&a=c&a=d');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('omits object key/value pair when value is empty array', function (st) {
|
||||
st.equal(qs.stringify({ a: [], b: 'zz' }), 'b=zz');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('should not omit object key/value pair when value is empty array and when asked', function (st) {
|
||||
st.equal(qs.stringify({ a: [], b: 'zz' }), 'b=zz');
|
||||
st.equal(qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: false }), 'b=zz');
|
||||
st.equal(qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: true }), 'a[]&b=zz');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('should throw when allowEmptyArrays is not of type boolean', function (st) {
|
||||
st['throws'](
|
||||
function () { qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 'foobar' }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 0 }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: NaN }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st['throws'](
|
||||
function () { qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: null }); },
|
||||
TypeError
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('allowEmptyArrays + strictNullHandling', function (st) {
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ testEmptyArray: [] },
|
||||
{ strictNullHandling: true, allowEmptyArrays: true }
|
||||
),
|
||||
'testEmptyArray[]'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -155,11 +351,22 @@ test('stringify()', function (t) {
|
||||
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c&a[1]=d');
|
||||
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c&a[]=d');
|
||||
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c,d');
|
||||
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true }), 'a=c,d');
|
||||
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true }), 'a[0]=c&a[1]=d');
|
||||
|
||||
s2t.end();
|
||||
});
|
||||
|
||||
st.test('array with multiple items with a comma inside', function (s2t) {
|
||||
s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c%2Cd,e');
|
||||
s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma' }), 'a=c%2Cd%2Ce');
|
||||
|
||||
s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true }), 'a=c%2Cd,e');
|
||||
s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma', commaRoundTrip: true }), 'a=c%2Cd%2Ce');
|
||||
|
||||
s2t.end();
|
||||
});
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -171,6 +378,44 @@ test('stringify()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('stringifies comma and empty array values', function (st) {
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'indices' }), 'a[0]=,&a[1]=&a[2]=c,d%');
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'brackets' }), 'a[]=,&a[]=&a[]=c,d%');
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'comma' }), 'a=,,,c,d%');
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'repeat' }), 'a=,&a=&a=c,d%');
|
||||
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=%2C&a[1]=&a[2]=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=%2C&a[]=&a[]=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=%2C,,c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a=%2C&a=&a=c%2Cd%25');
|
||||
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }), 'a%5B0%5D=%2C&a%5B1%5D=&a%5B2%5D=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' }), 'a%5B%5D=%2C&a%5B%5D=&a%5B%5D=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }), 'a=%2C%2C%2Cc%2Cd%25');
|
||||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }), 'a=%2C&a=&a=c%2Cd%25');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('stringifies comma and empty non-array values', function (st) {
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'indices' }), 'a=,&b=&c=c,d%');
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'brackets' }), 'a=,&b=&c=c,d%');
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'comma' }), 'a=,&b=&c=c,d%');
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'repeat' }), 'a=,&b=&c=c,d%');
|
||||
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'indices' }), 'a=%2C&b=&c=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a=%2C&b=&c=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=%2C&b=&c=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a=%2C&b=&c=c%2Cd%25');
|
||||
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }), 'a=%2C&b=&c=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' }), 'a=%2C&b=&c=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }), 'a=%2C&b=&c=c%2Cd%25');
|
||||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }), 'a=%2C&b=&c=c%2Cd%25');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('stringifies a nested array value with dots notation', function (st) {
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
@@ -209,36 +454,44 @@ test('stringify()', function (t) {
|
||||
|
||||
t.test('stringifies an object inside an array', function (st) {
|
||||
st.equal(
|
||||
qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices' }),
|
||||
'a%5B0%5D%5Bb%5D=c', // a[0][b]=c
|
||||
'indices => brackets'
|
||||
qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices', encodeValuesOnly: true }),
|
||||
'a[0][b]=c',
|
||||
'indices => indices'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets' }),
|
||||
'a%5B%5D%5Bb%5D=c', // a[][b]=c
|
||||
qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'repeat', encodeValuesOnly: true }),
|
||||
'a[b]=c',
|
||||
'repeat => repeat'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets', encodeValuesOnly: true }),
|
||||
'a[][b]=c',
|
||||
'brackets => brackets'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify({ a: [{ b: 'c' }] }),
|
||||
'a%5B0%5D%5Bb%5D=c',
|
||||
qs.stringify({ a: [{ b: 'c' }] }, { encodeValuesOnly: true }),
|
||||
'a[0][b]=c',
|
||||
'default => indices'
|
||||
);
|
||||
|
||||
st.equal(
|
||||
qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices' }),
|
||||
'a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1',
|
||||
qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices', encodeValuesOnly: true }),
|
||||
'a[0][b][c][0]=1',
|
||||
'indices => indices'
|
||||
);
|
||||
|
||||
st.equal(
|
||||
qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets' }),
|
||||
'a%5B%5D%5Bb%5D%5Bc%5D%5B%5D=1',
|
||||
qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'repeat', encodeValuesOnly: true }),
|
||||
'a[b][c]=1',
|
||||
'repeat => repeat'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets', encodeValuesOnly: true }),
|
||||
'a[][b][c][]=1',
|
||||
'brackets => brackets'
|
||||
);
|
||||
|
||||
st.equal(
|
||||
qs.stringify({ a: [{ b: { c: [1] } }] }),
|
||||
'a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1',
|
||||
qs.stringify({ a: [{ b: { c: [1] } }] }, { encodeValuesOnly: true }),
|
||||
'a[0][b][c][0]=1',
|
||||
'default => indices'
|
||||
);
|
||||
|
||||
@@ -340,17 +593,17 @@ test('stringify()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('uses indices notation for arrays when no arrayFormat=indices', function (st) {
|
||||
t.test('uses indices notation for arrays when arrayFormat=indices', function (st) {
|
||||
st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' }), 'a%5B0%5D=b&a%5B1%5D=c');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('uses repeat notation for arrays when no arrayFormat=repeat', function (st) {
|
||||
t.test('uses repeat notation for arrays when arrayFormat=repeat', function (st) {
|
||||
st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' }), 'a=b&a=c');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('uses brackets notation for arrays when no arrayFormat=brackets', function (st) {
|
||||
t.test('uses brackets notation for arrays when arrayFormat=brackets', function (st) {
|
||||
st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' }), 'a%5B%5D=b&a%5B%5D=c');
|
||||
st.end();
|
||||
});
|
||||
@@ -447,10 +700,11 @@ test('stringify()', function (t) {
|
||||
});
|
||||
|
||||
t.test('skips properties that are part of the object prototype', function (st) {
|
||||
Object.prototype.crash = 'test';
|
||||
st.intercept(Object.prototype, 'crash', { value: 'test' });
|
||||
|
||||
st.equal(qs.stringify({ a: 'b' }), 'a=b');
|
||||
st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
|
||||
delete Object.prototype.crash;
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -474,10 +728,12 @@ test('stringify()', function (t) {
|
||||
});
|
||||
|
||||
t.test('does not blow up when Buffer global is missing', function (st) {
|
||||
var tempBuffer = global.Buffer;
|
||||
delete global.Buffer;
|
||||
var restore = mockProperty(global, 'Buffer', { 'delete': true });
|
||||
|
||||
var result = qs.stringify({ a: 'b', c: 'd' });
|
||||
global.Buffer = tempBuffer;
|
||||
|
||||
restore();
|
||||
|
||||
st.equal(result, 'a=b&c=d');
|
||||
st.end();
|
||||
});
|
||||
@@ -526,9 +782,17 @@ test('stringify()', function (t) {
|
||||
};
|
||||
|
||||
st.equal(
|
||||
qs.stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true }),
|
||||
qs.stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
||||
'filters[$and][0][function]=gte&filters[$and][0][arguments][0][function]=hour_of_day&filters[$and][0][arguments][1]=0&filters[$and][1][function]=lte&filters[$and][1][arguments][0][function]=hour_of_day&filters[$and][1][arguments][1]=23'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
||||
'filters[$and][][function]=gte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=0&filters[$and][][function]=lte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=23'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),
|
||||
'filters[$and][function]=gte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=0&filters[$and][function]=lte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=23'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
@@ -641,13 +905,28 @@ test('stringify()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('receives the default encoder as a second argument', function (st) {
|
||||
st.plan(8);
|
||||
|
||||
qs.stringify({ a: 1, b: new Date(), c: true, d: [1] }, {
|
||||
encoder: function (str) {
|
||||
st.match(typeof str, /^(?:string|number|boolean)$/);
|
||||
return '';
|
||||
}
|
||||
});
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('receives the default encoder as a second argument', function (st) {
|
||||
st.plan(2);
|
||||
|
||||
qs.stringify({ a: 1 }, {
|
||||
encoder: function (str, defaultEncoder) {
|
||||
st.equal(defaultEncoder, utils.encode);
|
||||
}
|
||||
});
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -775,16 +1054,53 @@ test('stringify()', function (t) {
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
||||
{ encodeValuesOnly: true }
|
||||
{ encodeValuesOnly: true, arrayFormat: 'indices' }
|
||||
),
|
||||
'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h'
|
||||
'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h',
|
||||
'encodeValuesOnly + indices'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }
|
||||
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
||||
{ encodeValuesOnly: true, arrayFormat: 'brackets' }
|
||||
),
|
||||
'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h'
|
||||
'a=b&c[]=d&c[]=e%3Df&f[][]=g&f[][]=h',
|
||||
'encodeValuesOnly + brackets'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
||||
{ encodeValuesOnly: true, arrayFormat: 'repeat' }
|
||||
),
|
||||
'a=b&c=d&c=e%3Df&f=g&f=h',
|
||||
'encodeValuesOnly + repeat'
|
||||
);
|
||||
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] },
|
||||
{ arrayFormat: 'indices' }
|
||||
),
|
||||
'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h',
|
||||
'no encodeValuesOnly + indices'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] },
|
||||
{ arrayFormat: 'brackets' }
|
||||
),
|
||||
'a=b&c%5B%5D=d&c%5B%5D=e&f%5B%5D%5B%5D=g&f%5B%5D%5B%5D=h',
|
||||
'no encodeValuesOnly + brackets'
|
||||
);
|
||||
st.equal(
|
||||
qs.stringify(
|
||||
{ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] },
|
||||
{ arrayFormat: 'repeat' }
|
||||
),
|
||||
'a=b&c=d&c=e&f=g&f=h',
|
||||
'no encodeValuesOnly + repeat'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -821,13 +1137,19 @@ test('stringify()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('adds the right sentinel when instructed to and the charset is utf-8', function (st) {
|
||||
st.equal(qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' }), 'utf8=%E2%9C%93&a=%C3%A6');
|
||||
st.end();
|
||||
});
|
||||
t.test('`charsetSentinel` option', function (st) {
|
||||
st.equal(
|
||||
qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' }),
|
||||
'utf8=%E2%9C%93&a=%C3%A6',
|
||||
'adds the right sentinel when instructed to and the charset is utf-8'
|
||||
);
|
||||
|
||||
st.equal(
|
||||
qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' }),
|
||||
'utf8=%26%2310003%3B&a=%E6',
|
||||
'adds the right sentinel when instructed to and the charset is iso-8859-1'
|
||||
);
|
||||
|
||||
t.test('adds the right sentinel when instructed to and the charset is iso-8859-1', function (st) {
|
||||
st.equal(qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' }), 'utf8=%26%2310003%3B&a=%E6');
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -878,13 +1200,15 @@ test('stringify()', function (t) {
|
||||
var withArray = { a: { b: [{ c: 'd', e: 'f' }] } };
|
||||
|
||||
st.equal(qs.stringify(obj, { encode: false }), 'a[b][c]=d&a[b][e]=f', 'no array, no arrayFormat');
|
||||
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'bracket' }), 'a[b][c]=d&a[b][e]=f', 'no array, bracket');
|
||||
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'brackets' }), 'a[b][c]=d&a[b][e]=f', 'no array, bracket');
|
||||
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'indices' }), 'a[b][c]=d&a[b][e]=f', 'no array, indices');
|
||||
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'repeat' }), 'a[b][c]=d&a[b][e]=f', 'no array, repeat');
|
||||
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'comma' }), 'a[b][c]=d&a[b][e]=f', 'no array, comma');
|
||||
|
||||
st.equal(qs.stringify(withArray, { encode: false }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, no arrayFormat');
|
||||
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'bracket' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, bracket');
|
||||
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'brackets' }), 'a[b][][c]=d&a[b][][e]=f', 'array, bracket');
|
||||
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'indices' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, indices');
|
||||
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'repeat' }), 'a[b][c]=d&a[b][e]=f', 'array, repeat');
|
||||
st.equal(
|
||||
qs.stringify(withArray, { encode: false, arrayFormat: 'comma' }),
|
||||
'???',
|
||||
@@ -897,13 +1221,78 @@ test('stringify()', function (t) {
|
||||
|
||||
t.test('stringifies sparse arrays', function (st) {
|
||||
/* eslint no-sparse-arrays: 0 */
|
||||
st.equal(qs.stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true }), 'a[1]=2&a[4]=1');
|
||||
st.equal(qs.stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true }), 'a[1][b][2][c]=1');
|
||||
st.equal(qs.stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true }), 'a[1][2][3][c]=1');
|
||||
st.equal(qs.stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true }), 'a[1][2][3][c][1]=1');
|
||||
st.equal(qs.stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[1]=2&a[4]=1');
|
||||
st.equal(qs.stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=2&a[]=1');
|
||||
st.equal(qs.stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a=2&a=1');
|
||||
|
||||
st.equal(qs.stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[1][b][2][c]=1');
|
||||
st.equal(qs.stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[][b][][c]=1');
|
||||
st.equal(qs.stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a[b][c]=1');
|
||||
|
||||
st.equal(qs.stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[1][2][3][c]=1');
|
||||
st.equal(qs.stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[][][][c]=1');
|
||||
st.equal(qs.stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a[c]=1');
|
||||
|
||||
st.equal(qs.stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[1][2][3][c][1]=1');
|
||||
st.equal(qs.stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[][][][c][]=1');
|
||||
st.equal(qs.stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a[c]=1');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('encodes a very long string', function (st) {
|
||||
var chars = [];
|
||||
var expected = [];
|
||||
for (var i = 0; i < 5e3; i++) {
|
||||
chars.push(' ' + i);
|
||||
|
||||
expected.push('%20' + i);
|
||||
}
|
||||
|
||||
var obj = {
|
||||
foo: chars.join('')
|
||||
};
|
||||
|
||||
st.equal(
|
||||
qs.stringify(obj, { arrayFormat: 'bracket', charset: 'utf-8' }),
|
||||
'foo=' + expected.join('')
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('stringifies empty keys', function (t) {
|
||||
emptyTestCases.forEach(function (testCase) {
|
||||
t.test('stringifies an object with empty string key with ' + testCase.input, function (st) {
|
||||
st.deepEqual(
|
||||
qs.stringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'indices' }),
|
||||
testCase.stringifyOutput.indices,
|
||||
'test case: ' + testCase.input + ', indices'
|
||||
);
|
||||
st.deepEqual(
|
||||
qs.stringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'brackets' }),
|
||||
testCase.stringifyOutput.brackets,
|
||||
'test case: ' + testCase.input + ', brackets'
|
||||
);
|
||||
st.deepEqual(
|
||||
qs.stringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'repeat' }),
|
||||
testCase.stringifyOutput.repeat,
|
||||
'test case: ' + testCase.input + ', repeat'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
});
|
||||
|
||||
t.test('edge case with object/arrays', function (st) {
|
||||
st.deepEqual(qs.stringify({ '': { '': [2, 3] } }, { encode: false }), '[][0]=2&[][1]=3');
|
||||
st.deepEqual(qs.stringify({ '': { '': [2, 3], a: 2 } }, { encode: false }), '[][0]=2&[][1]=3&[a]=2');
|
||||
st.deepEqual(qs.stringify({ '': { '': [2, 3] } }, { encode: false, arrayFormat: 'indices' }), '[][0]=2&[][1]=3');
|
||||
st.deepEqual(qs.stringify({ '': { '': [2, 3], a: 2 } }, { encode: false, arrayFormat: 'indices' }), '[][0]=2&[][1]=3&[a]=2');
|
||||
|
||||
st.end();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user