qs 6.3.3 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc +4 -23
- package/.jscs.json +176 -0
- package/CHANGELOG.md +16 -24
- package/LICENSE +28 -0
- package/README.md +10 -25
- package/dist/qs.js +54 -59
- package/lib/formats.js +1 -1
- package/lib/parse.js +10 -11
- package/lib/stringify.js +30 -30
- package/lib/utils.js +11 -15
- package/package.json +48 -52
- package/test/.eslintrc +11 -0
- package/test/parse.js +6 -74
- package/test/stringify.js +37 -38
- package/test/utils.js +0 -7
- package/.editorconfig +0 -44
- package/.github/FUNDING.yml +0 -12
- package/.nycrc +0 -13
- package/LICENSE.md +0 -29
- package/bower.json +0 -21
- package/component.json +0 -15
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dist
|
package/.eslintrc
CHANGED
|
@@ -3,35 +3,16 @@
|
|
|
3
3
|
|
|
4
4
|
"extends": "@ljharb",
|
|
5
5
|
|
|
6
|
-
"ignorePatterns": [
|
|
7
|
-
"dist/",
|
|
8
|
-
],
|
|
9
|
-
|
|
10
6
|
"rules": {
|
|
11
|
-
"complexity": [2,
|
|
7
|
+
"complexity": [2, 26],
|
|
12
8
|
"consistent-return": 1,
|
|
13
|
-
"func-name-matching": 0,
|
|
14
9
|
"id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
|
|
15
10
|
"indent": [2, 4],
|
|
16
|
-
"max-lines-per-function": 0,
|
|
17
11
|
"max-params": [2, 12],
|
|
18
|
-
"max-statements": [2,
|
|
19
|
-
"multiline-comment-style": 0,
|
|
12
|
+
"max-statements": [2, 43],
|
|
20
13
|
"no-continue": 1,
|
|
21
14
|
"no-magic-numbers": 0,
|
|
22
|
-
"no-param-reassign": 1,
|
|
23
15
|
"no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"overrides": [
|
|
27
|
-
{
|
|
28
|
-
"files": "test/**",
|
|
29
|
-
"rules": {
|
|
30
|
-
"max-lines-per-function": 0,
|
|
31
|
-
"max-statements": 0,
|
|
32
|
-
"no-extend-native": 0,
|
|
33
|
-
"function-paren-newline": 0,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
],
|
|
16
|
+
"operator-linebreak": [2, "after"],
|
|
17
|
+
}
|
|
37
18
|
}
|
package/.jscs.json
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
{
|
|
2
|
+
"es3": true,
|
|
3
|
+
|
|
4
|
+
"additionalRules": [],
|
|
5
|
+
|
|
6
|
+
"requireSemicolons": true,
|
|
7
|
+
|
|
8
|
+
"disallowMultipleSpaces": true,
|
|
9
|
+
|
|
10
|
+
"disallowIdentifierNames": [],
|
|
11
|
+
|
|
12
|
+
"requireCurlyBraces": {
|
|
13
|
+
"allExcept": [],
|
|
14
|
+
"keywords": ["if", "else", "for", "while", "do", "try", "catch"]
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"],
|
|
18
|
+
|
|
19
|
+
"disallowSpaceAfterKeywords": [],
|
|
20
|
+
|
|
21
|
+
"disallowSpaceBeforeComma": true,
|
|
22
|
+
"disallowSpaceAfterComma": false,
|
|
23
|
+
"disallowSpaceBeforeSemicolon": true,
|
|
24
|
+
|
|
25
|
+
"disallowNodeTypes": [
|
|
26
|
+
"DebuggerStatement",
|
|
27
|
+
"ForInStatement",
|
|
28
|
+
"LabeledStatement",
|
|
29
|
+
"SwitchCase",
|
|
30
|
+
"SwitchStatement",
|
|
31
|
+
"WithStatement"
|
|
32
|
+
],
|
|
33
|
+
|
|
34
|
+
"requireObjectKeysOnNewLine": { "allExcept": ["sameLine"] },
|
|
35
|
+
|
|
36
|
+
"requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true },
|
|
37
|
+
"requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true },
|
|
38
|
+
"disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true },
|
|
39
|
+
"requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true },
|
|
40
|
+
"disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true },
|
|
41
|
+
|
|
42
|
+
"requireSpaceBetweenArguments": true,
|
|
43
|
+
|
|
44
|
+
"disallowSpacesInsideParentheses": true,
|
|
45
|
+
|
|
46
|
+
"disallowSpacesInsideArrayBrackets": true,
|
|
47
|
+
|
|
48
|
+
"disallowQuotedKeysInObjects": { "allExcept": ["reserved"] },
|
|
49
|
+
|
|
50
|
+
"disallowSpaceAfterObjectKeys": true,
|
|
51
|
+
|
|
52
|
+
"requireCommaBeforeLineBreak": true,
|
|
53
|
+
|
|
54
|
+
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
|
|
55
|
+
"requireSpaceAfterPrefixUnaryOperators": [],
|
|
56
|
+
|
|
57
|
+
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
|
|
58
|
+
"requireSpaceBeforePostfixUnaryOperators": [],
|
|
59
|
+
|
|
60
|
+
"disallowSpaceBeforeBinaryOperators": [],
|
|
61
|
+
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
|
|
62
|
+
|
|
63
|
+
"requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
|
|
64
|
+
"disallowSpaceAfterBinaryOperators": [],
|
|
65
|
+
|
|
66
|
+
"disallowImplicitTypeConversion": ["binary", "string"],
|
|
67
|
+
|
|
68
|
+
"disallowKeywords": ["with", "eval"],
|
|
69
|
+
|
|
70
|
+
"requireKeywordsOnNewLine": [],
|
|
71
|
+
"disallowKeywordsOnNewLine": ["else"],
|
|
72
|
+
|
|
73
|
+
"requireLineFeedAtFileEnd": true,
|
|
74
|
+
|
|
75
|
+
"disallowTrailingWhitespace": true,
|
|
76
|
+
|
|
77
|
+
"disallowTrailingComma": true,
|
|
78
|
+
|
|
79
|
+
"excludeFiles": ["node_modules/**", "vendor/**"],
|
|
80
|
+
|
|
81
|
+
"disallowMultipleLineStrings": true,
|
|
82
|
+
|
|
83
|
+
"requireDotNotation": { "allExcept": ["keywords"] },
|
|
84
|
+
|
|
85
|
+
"requireParenthesesAroundIIFE": true,
|
|
86
|
+
|
|
87
|
+
"validateLineBreaks": "LF",
|
|
88
|
+
|
|
89
|
+
"validateQuoteMarks": {
|
|
90
|
+
"escape": true,
|
|
91
|
+
"mark": "'"
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
"disallowOperatorBeforeLineBreak": [],
|
|
95
|
+
|
|
96
|
+
"requireSpaceBeforeKeywords": [
|
|
97
|
+
"do",
|
|
98
|
+
"for",
|
|
99
|
+
"if",
|
|
100
|
+
"else",
|
|
101
|
+
"switch",
|
|
102
|
+
"case",
|
|
103
|
+
"try",
|
|
104
|
+
"catch",
|
|
105
|
+
"finally",
|
|
106
|
+
"while",
|
|
107
|
+
"with",
|
|
108
|
+
"return"
|
|
109
|
+
],
|
|
110
|
+
|
|
111
|
+
"validateAlignedFunctionParameters": {
|
|
112
|
+
"lineBreakAfterOpeningBraces": true,
|
|
113
|
+
"lineBreakBeforeClosingBraces": true
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
"requirePaddingNewLinesBeforeExport": true,
|
|
117
|
+
|
|
118
|
+
"validateNewlineAfterArrayElements": {
|
|
119
|
+
"maximum": 1
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
"requirePaddingNewLinesAfterUseStrict": true,
|
|
123
|
+
|
|
124
|
+
"disallowArrowFunctions": true,
|
|
125
|
+
|
|
126
|
+
"disallowMultiLineTernary": true,
|
|
127
|
+
|
|
128
|
+
"validateOrderInObjectKeys": "asc-insensitive",
|
|
129
|
+
|
|
130
|
+
"disallowIdenticalDestructuringNames": true,
|
|
131
|
+
|
|
132
|
+
"disallowNestedTernaries": { "maxLevel": 1 },
|
|
133
|
+
|
|
134
|
+
"requireSpaceAfterComma": { "allExcept": ["trailing"] },
|
|
135
|
+
"requireAlignedMultilineParams": false,
|
|
136
|
+
|
|
137
|
+
"requireSpacesInGenerator": {
|
|
138
|
+
"afterStar": true
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
"disallowSpacesInGenerator": {
|
|
142
|
+
"beforeStar": true
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
"disallowVar": false,
|
|
146
|
+
|
|
147
|
+
"requireArrayDestructuring": false,
|
|
148
|
+
|
|
149
|
+
"requireEnhancedObjectLiterals": false,
|
|
150
|
+
|
|
151
|
+
"requireObjectDestructuring": false,
|
|
152
|
+
|
|
153
|
+
"requireEarlyReturn": false,
|
|
154
|
+
|
|
155
|
+
"requireCapitalizedConstructorsNew": {
|
|
156
|
+
"allExcept": ["Function", "String", "Object", "Symbol", "Number", "Date", "RegExp", "Error", "Boolean", "Array"]
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
"requireImportAlphabetized": false,
|
|
160
|
+
|
|
161
|
+
"requireSpaceBeforeObjectValues": true,
|
|
162
|
+
"requireSpaceBeforeDestructuredValues": true,
|
|
163
|
+
|
|
164
|
+
"disallowSpacesInsideTemplateStringPlaceholders": true,
|
|
165
|
+
|
|
166
|
+
"disallowArrayDestructuringReturn": false,
|
|
167
|
+
|
|
168
|
+
"requireNewlineBeforeSingleStatementsInIf": false,
|
|
169
|
+
|
|
170
|
+
"disallowUnusedVariables": true,
|
|
171
|
+
|
|
172
|
+
"requireSpacesInsideImportedObjectBraces": true,
|
|
173
|
+
|
|
174
|
+
"requireUseStrict": true
|
|
175
|
+
}
|
|
176
|
+
|
package/CHANGELOG.md
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
|
-
## **6.
|
|
2
|
-
- [
|
|
3
|
-
- [Fix]
|
|
4
|
-
- [Fix] `utils.merge`: avoid a crash with a null target and an array source
|
|
5
|
-
- [Fix]` `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
|
6
|
-
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
|
|
7
|
-
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
|
8
|
-
- [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
|
|
9
|
-
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
|
10
|
-
- [Refactor] use cached `Array.isArray`
|
|
11
|
-
- [Refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
|
|
12
|
-
- [Docs] Clarify the need for "arrayLimit" option
|
|
13
|
-
- [meta] fix README.md (#399)
|
|
14
|
-
- [meta] Clean up license text so it’s properly detected as BSD-3-Clause
|
|
15
|
-
- [meta] add FUNDING.yml
|
|
16
|
-
- [actions] backport actions from main
|
|
17
|
-
- [Tests] use `safer-buffer` instead of `Buffer` constructor
|
|
18
|
-
- [Tests] remove nonexistent tape option
|
|
19
|
-
- [Dev Deps] backport from main
|
|
20
|
-
|
|
21
|
-
## **6.3.2**
|
|
22
|
-
- [Fix] follow `allowPrototypes` option during merge (#201, #200)
|
|
23
|
-
- [Dev Deps] update `eslint`
|
|
24
|
-
- [Fix] chmod a-x
|
|
1
|
+
## **6.4.0**
|
|
2
|
+
- [New] `qs.stringify`: add `encodeValuesOnly` option
|
|
3
|
+
- [Fix] follow `allowPrototypes` option during merge (#201, #201)
|
|
25
4
|
- [Fix] support keys starting with brackets (#202, #200)
|
|
5
|
+
- [Fix] chmod a-x
|
|
6
|
+
- [Dev Deps] update `eslint`
|
|
26
7
|
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
|
|
8
|
+
- [eslint] reduce warnings
|
|
27
9
|
|
|
28
10
|
## **6.3.1**
|
|
29
11
|
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties (thanks, @snyk!)
|
|
@@ -51,6 +33,9 @@
|
|
|
51
33
|
- [Tests] skip Object.create tests when null objects are not available
|
|
52
34
|
- [Tests] Turn on eslint for test files (#175)
|
|
53
35
|
|
|
36
|
+
## **6.2.2**
|
|
37
|
+
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
|
|
38
|
+
|
|
54
39
|
## **6.2.1**
|
|
55
40
|
- [Fix] ensure `key[]=x&key[]&key[]=y` results in 3, not 2, values
|
|
56
41
|
- [Refactor] Be explicit and use `Object.prototype.hasOwnProperty.call`
|
|
@@ -63,11 +48,18 @@
|
|
|
63
48
|
- [New] add "encoder" and "decoder" options, for custom param encoding/decoding (#160)
|
|
64
49
|
- [Fix] fix compacting of nested sparse arrays (#150)
|
|
65
50
|
|
|
51
|
+
## **6.1.1**
|
|
52
|
+
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
|
|
53
|
+
|
|
66
54
|
## [**6.1.0**](https://github.com/ljharb/qs/issues?milestone=35&state=closed)
|
|
67
55
|
- [New] allowDots option for `stringify` (#151)
|
|
68
56
|
- [Fix] "sort" option should work at a depth of 3 or more (#151)
|
|
69
57
|
- [Fix] Restore `dist` directory; will be removed in v7 (#148)
|
|
70
58
|
|
|
59
|
+
## **6.0.3**
|
|
60
|
+
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
|
|
61
|
+
- [Fix] Restore `dist` directory; will be removed in v7 (#148)
|
|
62
|
+
|
|
71
63
|
## [**6.0.2**](https://github.com/ljharb/qs/issues?milestone=33&state=closed)
|
|
72
64
|
- Revert ES6 requirement and restore support for node down to v0.8.
|
|
73
65
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Copyright (c) 2014 Nathan LaFreniere and other contributors.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
* Redistributions of source code must retain the above copyright
|
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
|
10
|
+
documentation and/or other materials provided with the distribution.
|
|
11
|
+
* The names of any contributors may not be used to endorse or promote
|
|
12
|
+
products derived from this software without specific prior written
|
|
13
|
+
permission.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
|
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
25
|
+
|
|
26
|
+
* * *
|
|
27
|
+
|
|
28
|
+
The complete list of contributors can be found at: https://github.com/hapijs/qs/graphs/contributors
|
package/README.md
CHANGED
|
@@ -169,7 +169,7 @@ assert.deepEqual(withIndexedEmptyString, { a: ['b', '', 'c'] });
|
|
|
169
169
|
```
|
|
170
170
|
|
|
171
171
|
**qs** will also limit specifying indices in an array to a maximum index of `20`. Any array members with an index of greater than `20` will
|
|
172
|
-
instead be converted to an object with the index as the key
|
|
172
|
+
instead be converted to an object with the index as the key:
|
|
173
173
|
|
|
174
174
|
```javascript
|
|
175
175
|
var withMaxIndex = qs.parse('a[100]=b');
|
|
@@ -225,6 +225,15 @@ var unencoded = qs.stringify({ a: { b: 'c' } }, { encode: false });
|
|
|
225
225
|
assert.equal(unencoded, 'a[b]=c');
|
|
226
226
|
```
|
|
227
227
|
|
|
228
|
+
Encoding can be disabled for keys by setting the `encodeValuesOnly` option to `true`:
|
|
229
|
+
```javascript
|
|
230
|
+
var encodedValues = qs.stringify(
|
|
231
|
+
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
|
232
|
+
{ encodeValuesOnly: true }
|
|
233
|
+
)
|
|
234
|
+
assert.equal(encodedValues,'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h');
|
|
235
|
+
```
|
|
236
|
+
|
|
228
237
|
This encoding can also be replaced by a custom encoding method set as `encoder` option:
|
|
229
238
|
|
|
230
239
|
```javascript
|
|
@@ -245,30 +254,6 @@ var decoded = qs.parse('x=z', { decoder: function (str) {
|
|
|
245
254
|
}})
|
|
246
255
|
```
|
|
247
256
|
|
|
248
|
-
You can encode keys and values using different logic by using the type argument provided to the encoder:
|
|
249
|
-
|
|
250
|
-
```javascript
|
|
251
|
-
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) {
|
|
252
|
-
if (type === 'key') {
|
|
253
|
-
return // Encoded key
|
|
254
|
-
} else if (type === 'value') {
|
|
255
|
-
return // Encoded value
|
|
256
|
-
}
|
|
257
|
-
}})
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
The type argument is also provided to the decoder:
|
|
261
|
-
|
|
262
|
-
```javascript
|
|
263
|
-
var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) {
|
|
264
|
-
if (type === 'key') {
|
|
265
|
-
return // Decoded key
|
|
266
|
-
} else if (type === 'value') {
|
|
267
|
-
return // Decoded value
|
|
268
|
-
}
|
|
269
|
-
}})
|
|
270
|
-
```
|
|
271
|
-
|
|
272
257
|
Examples beyond this point will be shown as though the output is not URI encoded for clarity. Please note that the return values in these cases *will* be URI encoded during real usage.
|
|
273
258
|
|
|
274
259
|
When arrays are stringified, by default they are given explicit indices:
|
package/dist/qs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function
|
|
1
|
+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var replace = String.prototype.replace;
|
|
@@ -11,7 +11,7 @@ module.exports = {
|
|
|
11
11
|
return replace.call(value, percentTwenties, '+');
|
|
12
12
|
},
|
|
13
13
|
RFC3986: function (value) {
|
|
14
|
-
return
|
|
14
|
+
return value;
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
RFC1738: 'RFC1738',
|
|
@@ -84,25 +84,23 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
|
|
|
84
84
|
var root = chain.shift();
|
|
85
85
|
|
|
86
86
|
var obj;
|
|
87
|
-
if (root === '[]'
|
|
87
|
+
if (root === '[]') {
|
|
88
88
|
obj = [];
|
|
89
89
|
obj = obj.concat(parseObject(chain, val, options));
|
|
90
90
|
} else {
|
|
91
91
|
obj = options.plainObjects ? Object.create(null) : {};
|
|
92
92
|
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
|
93
93
|
var index = parseInt(cleanRoot, 10);
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
&&
|
|
100
|
-
&& index >= 0
|
|
101
|
-
&& (options.parseArrays && index <= options.arrayLimit)
|
|
94
|
+
if (
|
|
95
|
+
!isNaN(index) &&
|
|
96
|
+
root !== cleanRoot &&
|
|
97
|
+
String(index) === cleanRoot &&
|
|
98
|
+
index >= 0 &&
|
|
99
|
+
(options.parseArrays && index <= options.arrayLimit)
|
|
102
100
|
) {
|
|
103
101
|
obj = [];
|
|
104
102
|
obj[index] = parseObject(chain, val, options);
|
|
105
|
-
} else
|
|
103
|
+
} else {
|
|
106
104
|
obj[cleanRoot] = parseObject(chain, val, options);
|
|
107
105
|
}
|
|
108
106
|
}
|
|
@@ -132,7 +130,8 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
|
|
|
132
130
|
|
|
133
131
|
var keys = [];
|
|
134
132
|
if (parent) {
|
|
135
|
-
// If we aren't using plain objects, optionally prefix keys
|
|
133
|
+
// If we aren't using plain objects, optionally prefix keys
|
|
134
|
+
// that would overwrite object prototype properties
|
|
136
135
|
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
|
137
136
|
if (!options.allowPrototypes) {
|
|
138
137
|
return;
|
|
@@ -208,37 +207,32 @@ var utils = require('./utils');
|
|
|
208
207
|
var formats = require('./formats');
|
|
209
208
|
|
|
210
209
|
var arrayPrefixGenerators = {
|
|
211
|
-
brackets: function brackets(prefix) {
|
|
210
|
+
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
|
|
212
211
|
return prefix + '[]';
|
|
213
212
|
},
|
|
214
|
-
indices: function indices(prefix, key) {
|
|
213
|
+
indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
|
|
215
214
|
return prefix + '[' + key + ']';
|
|
216
215
|
},
|
|
217
|
-
repeat: function repeat(prefix) {
|
|
216
|
+
repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
|
|
218
217
|
return prefix;
|
|
219
218
|
}
|
|
220
219
|
};
|
|
221
220
|
|
|
222
|
-
var isArray = Array.isArray;
|
|
223
|
-
var push = Array.prototype.push;
|
|
224
|
-
var pushToArray = function (arr, valueOrArray) {
|
|
225
|
-
push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
|
226
|
-
};
|
|
227
|
-
|
|
228
221
|
var toISO = Date.prototype.toISOString;
|
|
229
222
|
|
|
230
223
|
var defaults = {
|
|
231
224
|
delimiter: '&',
|
|
232
225
|
encode: true,
|
|
233
226
|
encoder: utils.encode,
|
|
234
|
-
|
|
227
|
+
encodeValuesOnly: false,
|
|
228
|
+
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
|
|
235
229
|
return toISO.call(date);
|
|
236
230
|
},
|
|
237
231
|
skipNulls: false,
|
|
238
232
|
strictNullHandling: false
|
|
239
233
|
};
|
|
240
234
|
|
|
241
|
-
var stringify = function stringify(
|
|
235
|
+
var stringify = function stringify( // eslint-disable-line func-name-matching
|
|
242
236
|
object,
|
|
243
237
|
prefix,
|
|
244
238
|
generateArrayPrefix,
|
|
@@ -249,18 +243,17 @@ var stringify = function stringify(
|
|
|
249
243
|
sort,
|
|
250
244
|
allowDots,
|
|
251
245
|
serializeDate,
|
|
252
|
-
formatter
|
|
246
|
+
formatter,
|
|
247
|
+
encodeValuesOnly
|
|
253
248
|
) {
|
|
254
249
|
var obj = object;
|
|
255
250
|
if (typeof filter === 'function') {
|
|
256
251
|
obj = filter(prefix, obj);
|
|
257
252
|
} else if (obj instanceof Date) {
|
|
258
253
|
obj = serializeDate(obj);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (obj === null) {
|
|
254
|
+
} else if (obj === null) {
|
|
262
255
|
if (strictNullHandling) {
|
|
263
|
-
return encoder ? encoder(prefix) : prefix;
|
|
256
|
+
return encoder && !encodeValuesOnly ? encoder(prefix) : prefix;
|
|
264
257
|
}
|
|
265
258
|
|
|
266
259
|
obj = '';
|
|
@@ -268,7 +261,8 @@ var stringify = function stringify(
|
|
|
268
261
|
|
|
269
262
|
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
|
|
270
263
|
if (encoder) {
|
|
271
|
-
|
|
264
|
+
var keyValue = encodeValuesOnly ? prefix : encoder(prefix);
|
|
265
|
+
return [formatter(keyValue) + '=' + formatter(encoder(obj))];
|
|
272
266
|
}
|
|
273
267
|
return [formatter(prefix) + '=' + formatter(String(obj))];
|
|
274
268
|
}
|
|
@@ -280,7 +274,7 @@ var stringify = function stringify(
|
|
|
280
274
|
}
|
|
281
275
|
|
|
282
276
|
var objKeys;
|
|
283
|
-
if (isArray(filter)) {
|
|
277
|
+
if (Array.isArray(filter)) {
|
|
284
278
|
objKeys = filter;
|
|
285
279
|
} else {
|
|
286
280
|
var keys = Object.keys(obj);
|
|
@@ -294,8 +288,8 @@ var stringify = function stringify(
|
|
|
294
288
|
continue;
|
|
295
289
|
}
|
|
296
290
|
|
|
297
|
-
if (isArray(obj)) {
|
|
298
|
-
|
|
291
|
+
if (Array.isArray(obj)) {
|
|
292
|
+
values = values.concat(stringify(
|
|
299
293
|
obj[key],
|
|
300
294
|
generateArrayPrefix(prefix, key),
|
|
301
295
|
generateArrayPrefix,
|
|
@@ -306,10 +300,11 @@ var stringify = function stringify(
|
|
|
306
300
|
sort,
|
|
307
301
|
allowDots,
|
|
308
302
|
serializeDate,
|
|
309
|
-
formatter
|
|
303
|
+
formatter,
|
|
304
|
+
encodeValuesOnly
|
|
310
305
|
));
|
|
311
306
|
} else {
|
|
312
|
-
|
|
307
|
+
values = values.concat(stringify(
|
|
313
308
|
obj[key],
|
|
314
309
|
prefix + (allowDots ? '.' + key : '[' + key + ']'),
|
|
315
310
|
generateArrayPrefix,
|
|
@@ -320,7 +315,8 @@ var stringify = function stringify(
|
|
|
320
315
|
sort,
|
|
321
316
|
allowDots,
|
|
322
317
|
serializeDate,
|
|
323
|
-
formatter
|
|
318
|
+
formatter,
|
|
319
|
+
encodeValuesOnly
|
|
324
320
|
));
|
|
325
321
|
}
|
|
326
322
|
}
|
|
@@ -332,7 +328,7 @@ module.exports = function (object, opts) {
|
|
|
332
328
|
var obj = object;
|
|
333
329
|
var options = opts || {};
|
|
334
330
|
|
|
335
|
-
if (options.encoder !== null &&
|
|
331
|
+
if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
|
|
336
332
|
throw new TypeError('Encoder has to be a function.');
|
|
337
333
|
}
|
|
338
334
|
|
|
@@ -340,12 +336,13 @@ module.exports = function (object, opts) {
|
|
|
340
336
|
var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
|
|
341
337
|
var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls;
|
|
342
338
|
var encode = typeof options.encode === 'boolean' ? options.encode : defaults.encode;
|
|
343
|
-
var encoder =
|
|
339
|
+
var encoder = typeof options.encoder === 'function' ? options.encoder : defaults.encoder;
|
|
344
340
|
var sort = typeof options.sort === 'function' ? options.sort : null;
|
|
345
341
|
var allowDots = typeof options.allowDots === 'undefined' ? false : options.allowDots;
|
|
346
342
|
var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
|
|
343
|
+
var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly;
|
|
347
344
|
if (typeof options.format === 'undefined') {
|
|
348
|
-
options.format = formats
|
|
345
|
+
options.format = formats.default;
|
|
349
346
|
} else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
|
|
350
347
|
throw new TypeError('Unknown format option provided.');
|
|
351
348
|
}
|
|
@@ -356,7 +353,7 @@ module.exports = function (object, opts) {
|
|
|
356
353
|
if (typeof options.filter === 'function') {
|
|
357
354
|
filter = options.filter;
|
|
358
355
|
obj = filter('', obj);
|
|
359
|
-
} else if (isArray(options.filter)) {
|
|
356
|
+
} else if (Array.isArray(options.filter)) {
|
|
360
357
|
filter = options.filter;
|
|
361
358
|
objKeys = filter;
|
|
362
359
|
}
|
|
@@ -392,18 +389,20 @@ module.exports = function (object, opts) {
|
|
|
392
389
|
if (skipNulls && obj[key] === null) {
|
|
393
390
|
continue;
|
|
394
391
|
}
|
|
395
|
-
|
|
392
|
+
|
|
393
|
+
keys = keys.concat(stringify(
|
|
396
394
|
obj[key],
|
|
397
395
|
key,
|
|
398
396
|
generateArrayPrefix,
|
|
399
397
|
strictNullHandling,
|
|
400
398
|
skipNulls,
|
|
401
|
-
encoder,
|
|
399
|
+
encode ? encoder : null,
|
|
402
400
|
filter,
|
|
403
401
|
sort,
|
|
404
402
|
allowDots,
|
|
405
403
|
serializeDate,
|
|
406
|
-
formatter
|
|
404
|
+
formatter,
|
|
405
|
+
encodeValuesOnly
|
|
407
406
|
));
|
|
408
407
|
}
|
|
409
408
|
|
|
@@ -443,8 +442,8 @@ exports.merge = function (target, source, options) {
|
|
|
443
442
|
if (typeof source !== 'object') {
|
|
444
443
|
if (Array.isArray(target)) {
|
|
445
444
|
target.push(source);
|
|
446
|
-
} else if (
|
|
447
|
-
if (
|
|
445
|
+
} else if (typeof target === 'object') {
|
|
446
|
+
if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
|
|
448
447
|
target[source] = true;
|
|
449
448
|
}
|
|
450
449
|
} else {
|
|
@@ -454,7 +453,7 @@ exports.merge = function (target, source, options) {
|
|
|
454
453
|
return target;
|
|
455
454
|
}
|
|
456
455
|
|
|
457
|
-
if (
|
|
456
|
+
if (typeof target !== 'object') {
|
|
458
457
|
return [target].concat(source);
|
|
459
458
|
}
|
|
460
459
|
|
|
@@ -512,13 +511,13 @@ exports.encode = function (str) {
|
|
|
512
511
|
var c = string.charCodeAt(i);
|
|
513
512
|
|
|
514
513
|
if (
|
|
515
|
-
c === 0x2D // -
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
514
|
+
c === 0x2D || // -
|
|
515
|
+
c === 0x2E || // .
|
|
516
|
+
c === 0x5F || // _
|
|
517
|
+
c === 0x7E || // ~
|
|
518
|
+
(c >= 0x30 && c <= 0x39) || // 0-9
|
|
519
|
+
(c >= 0x41 && c <= 0x5A) || // a-z
|
|
520
|
+
(c >= 0x61 && c <= 0x7A) // A-Z
|
|
522
521
|
) {
|
|
523
522
|
out += string.charAt(i);
|
|
524
523
|
continue;
|
|
@@ -541,11 +540,7 @@ exports.encode = function (str) {
|
|
|
541
540
|
|
|
542
541
|
i += 1;
|
|
543
542
|
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
|
|
544
|
-
|
|
545
|
-
out += hexTable[0xF0 | (c >> 18)]
|
|
546
|
-
+ hexTable[0x80 | ((c >> 12) & 0x3F)]
|
|
547
|
-
+ hexTable[0x80 | ((c >> 6) & 0x3F)]
|
|
548
|
-
+ hexTable[0x80 | (c & 0x3F)];
|
|
543
|
+
out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len
|
|
549
544
|
}
|
|
550
545
|
|
|
551
546
|
return out;
|
|
@@ -599,4 +594,4 @@ exports.isBuffer = function (obj) {
|
|
|
599
594
|
};
|
|
600
595
|
|
|
601
596
|
},{}]},{},[2])(2)
|
|
602
|
-
});
|
|
597
|
+
});
|