| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -122,8 +122,9 @@ The `querystring.stringify()` method produces a URL query string from a | |||
| 122 | 122 | given `obj` by iterating through the object's "own properties". | |
| 123 | 123 | ||
| 124 | 124 | It serializes the following types of values passed in `obj`: | |
| 125 | - {string|number|boolean|string[]|number[]|boolean[]} | ||
| 126 | - Any other input values will be coerced to empty strings. | ||
| 125 | + {string|number|bigint|boolean|string[]|number[]|bigint[]|boolean[]} | ||
| 126 | + The numeric values must be finite. Any other input values will be coerced to | ||
| 127 | + empty strings. | ||
| 127 | 128 | ||
| 128 | 129 | ```js | |
| 129 | 130 | querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -162,6 +162,8 @@ function stringifyPrimitive(v) { | |||
| 162 | 162 | return v; | |
| 163 | 163 | if (typeof v === 'number' && NumberIsFinite(v)) | |
| 164 | 164 | return '' + v; | |
| 165 | + if (typeof v === 'bigint') | ||
| 166 | + return '' + v; | ||
| 165 | 167 | if (typeof v === 'boolean') | |
| 166 | 168 | return v ? 'true' : 'false'; | |
| 167 | 169 | return ''; | |
@@ -176,6 +178,8 @@ function encodeStringified(v, encode) { | |||
| 176 | 178 | // escaping due to the inclusion of a '+' in the output | |
| 177 | 179 | return (MathAbs(v) < 1e21 ? '' + v : encode('' + v)); | |
| 178 | 180 | } | |
| 181 | + if (typeof v === 'bigint') | ||
| 182 | + return '' + v; | ||
| 179 | 183 | if (typeof v === 'boolean') | |
| 180 | 184 | return v ? 'true' : 'false'; | |
| 181 | 185 | return ''; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -273,6 +273,24 @@ qsWeirdObjects.forEach((testCase) => { | |||
| 273 | 273 | assert.strictEqual(qs.stringify(testCase[0]), testCase[1]); | |
| 274 | 274 | }); | |
| 275 | 275 | ||
| 276 | + // BigInt values | ||
| 277 | + | ||
| 278 | + assert.strictEqual(qs.stringify({ foo: 2n ** 1023n }), | ||
| 279 | + 'foo=' + 2n ** 1023n); | ||
| 280 | + assert.strictEqual(qs.stringify([0n, 1n, 2n]), | ||
| 281 | + '0=0&1=1&2=2'); | ||
| 282 | + | ||
| 283 | + assert.strictEqual(qs.stringify({ foo: 2n ** 1023n }, | ||
| 284 | + null, | ||
| 285 | + null, | ||
| 286 | + { encodeURIComponent: (c) => c }), | ||
| 287 | + 'foo=' + 2n ** 1023n); | ||
| 288 | + assert.strictEqual(qs.stringify([0n, 1n, 2n], | ||
| 289 | + null, | ||
| 290 | + null, | ||
| 291 | + { encodeURIComponent: (c) => c }), | ||
| 292 | + '0=0&1=1&2=2'); | ||
| 293 | + | ||
| 276 | 294 | // Invalid surrogate pair throws URIError | |
| 277 | 295 | assert.throws( | |
| 278 | 296 | () => qs.stringify({ foo: '\udc00' }), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments