@arokodev/cli 0.1.0-alpha.5 → 0.1.0-alpha.8
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/node_modules/@pairmesh/client/dist/build-info.generated.d.ts +12 -12
- package/node_modules/@pairmesh/client/dist/build-info.generated.js +6 -6
- package/node_modules/@pairmesh/client/dist/connectivity/relay/hosted-server.js +1 -1
- package/node_modules/@pairmesh/client/dist/session/schemas.d.ts +10 -10
- package/node_modules/@pairmesh/client/dist/session/schemas.d.ts.map +1 -1
- package/node_modules/@pairmesh/client/package.json +5 -5
- package/node_modules/@pairmesh/coordination/package.json +5 -5
- package/node_modules/@pairmesh/mcp/package.json +5 -5
- package/node_modules/@pairmesh/permissions/package.json +2 -2
- package/node_modules/@pairmesh/protocol/dist/action.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/inspection-execution.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/inspection-thread.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/inspection-thread.d.ts.map +1 -1
- package/node_modules/@pairmesh/protocol/dist/inspection.d.ts +2 -2
- package/node_modules/@pairmesh/protocol/dist/pairing.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/progress-event.d.ts +1 -1
- package/node_modules/@pairmesh/protocol/dist/progress-event.d.ts.map +1 -1
- package/node_modules/@pairmesh/protocol/package.json +2 -2
- package/node_modules/@pairmesh/shared/package.json +1 -1
- package/node_modules/body-parser/README.md +17 -13
- package/node_modules/body-parser/lib/read.js +74 -57
- package/node_modules/body-parser/lib/types/json.js +11 -11
- package/node_modules/body-parser/lib/types/urlencoded.js +5 -5
- package/node_modules/body-parser/lib/utils.js +0 -15
- package/node_modules/body-parser/package.json +7 -12
- package/node_modules/encodeurl/README.md +14 -0
- package/node_modules/encodeurl/index.js +9 -11
- package/node_modules/encodeurl/package.json +13 -6
- package/node_modules/jose/README.md +2 -2
- package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +5 -4
- package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -4
- package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +5 -4
- package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +5 -5
- package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +5 -4
- package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +5 -5
- package/node_modules/jose/dist/types/jws/compact/sign.d.ts +5 -4
- package/node_modules/jose/dist/types/jws/compact/verify.d.ts +5 -5
- package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +5 -4
- package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +6 -5
- package/node_modules/jose/dist/types/jws/general/sign.d.ts +9 -6
- package/node_modules/jose/dist/types/jws/general/verify.d.ts +7 -5
- package/node_modules/jose/dist/types/jwt/decrypt.d.ts +10 -6
- package/node_modules/jose/dist/types/jwt/encrypt.d.ts +1 -1
- package/node_modules/jose/dist/types/jwt/sign.d.ts +1 -1
- package/node_modules/jose/dist/types/jwt/unsecured.d.ts +3 -1
- package/node_modules/jose/dist/types/jwt/verify.d.ts +6 -5
- package/node_modules/jose/dist/types/key/export.d.ts +1 -1
- package/node_modules/jose/dist/types/key/generate_secret.d.ts +1 -1
- package/node_modules/jose/dist/types/key/import.d.ts +2 -2
- package/node_modules/jose/dist/types/types.d.ts +173 -107
- package/node_modules/jose/dist/types/util/decode_jwt.d.ts +3 -2
- package/node_modules/jose/dist/types/util/errors.d.ts +1 -1
- package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +3 -2
- package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +3 -3
- package/node_modules/jose/dist/webapi/jwk/thumbprint.js +8 -8
- package/node_modules/jose/dist/webapi/jwks/local.js +2 -1
- package/node_modules/jose/dist/webapi/jwks/remote.js +6 -4
- package/node_modules/jose/dist/webapi/jws/general/sign.js +3 -3
- package/node_modules/jose/dist/webapi/jws/general/verify.js +5 -11
- package/node_modules/jose/dist/webapi/jwt/encrypt.js +6 -9
- package/node_modules/jose/dist/webapi/jwt/sign.js +2 -2
- package/node_modules/jose/dist/webapi/jwt/unsecured.js +3 -3
- package/node_modules/jose/dist/webapi/key/generate_secret.js +4 -4
- package/node_modules/jose/dist/webapi/lib/asn1.js +2 -2
- package/node_modules/jose/dist/webapi/lib/buffer_utils.js +4 -4
- package/node_modules/jose/dist/webapi/lib/content_encryption.js +8 -8
- package/node_modules/jose/dist/webapi/lib/deflate.js +2 -1
- package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +26 -23
- package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +5 -5
- package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +2 -2
- package/node_modules/jose/dist/webapi/lib/jws_sign.js +11 -11
- package/node_modules/jose/dist/webapi/lib/jws_verify.js +19 -16
- package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +48 -44
- package/node_modules/jose/dist/webapi/lib/key.js +6 -4
- package/node_modules/jose/dist/webapi/lib/key_management.js +17 -18
- package/node_modules/jose/dist/webapi/lib/validate.js +10 -10
- package/node_modules/jose/dist/webapi/util/decode_jwt.js +12 -12
- package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -5
- package/node_modules/jose/package.json +1 -1
- package/node_modules/object-inspect/CHANGELOG.md +31 -0
- package/node_modules/object-inspect/index.js +326 -24
- package/node_modules/object-inspect/package.json +22 -13
- package/node_modules/object-inspect/readme.markdown +4 -1
- package/node_modules/object-inspect/stringWidth.js +68 -0
- package/node_modules/object-inspect/stringWidthRanges.js +38 -0
- package/node_modules/on-finished/index.js +14 -2
- package/node_modules/on-finished/package.json +11 -7
- package/node_modules/qs/.editorconfig +1 -1
- package/node_modules/qs/.github/THREAT_MODEL.md +4 -2
- package/node_modules/qs/CHANGELOG.md +103 -14
- package/node_modules/qs/README.md +90 -9
- package/node_modules/qs/dist/qs.js +19 -19
- package/node_modules/qs/eslint.config.mjs +61 -50
- package/node_modules/qs/lib/formats.js +7 -2
- package/node_modules/qs/lib/parse.js +121 -12
- package/node_modules/qs/lib/stringify.js +9 -7
- package/node_modules/qs/lib/utils.js +158 -15
- package/node_modules/qs/package.json +8 -8
- package/node_modules/qs/test/parse.js +509 -2
- package/node_modules/qs/test/stringify.js +485 -33
- package/node_modules/qs/test/utils.js +245 -3
- package/node_modules/router/HISTORY.md +67 -52
- package/node_modules/router/README.md +222 -2
- package/node_modules/router/index.d.ts +188 -0
- package/node_modules/router/index.js +86 -50
- package/node_modules/router/lib/layer.js +154 -47
- package/node_modules/router/lib/param.js +47 -0
- package/node_modules/router/lib/route.d.ts +118 -0
- package/node_modules/router/lib/route.js +14 -8
- package/node_modules/router/lib/symbols.js +4 -0
- package/node_modules/router/lib/tracing.js +173 -0
- package/node_modules/router/package.json +24 -9
- package/node_modules/ws/README.md +22 -31
- package/node_modules/ws/lib/buffer-util.js +13 -2
- package/node_modules/ws/lib/receiver.js +8 -0
- package/node_modules/ws/lib/sender.js +4 -1
- package/node_modules/ws/lib/websocket-server.js +3 -0
- package/node_modules/ws/lib/websocket.js +66 -16
- package/node_modules/ws/package.json +1 -1
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
- package/node_modules/zod/src/v4/core/compile.ts +9 -0
- package/node_modules/zod/src/v4/core/schemas.ts +35 -1
- package/node_modules/zod/src/v4/core/util.ts +13 -0
- package/node_modules/zod/src/v4/core/versions.ts +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.d.cts +3 -1
- package/node_modules/zod/v4/core/schemas.d.ts +3 -1
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.d.cts +2 -0
- package/node_modules/zod/v4/core/util.d.ts +2 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/package.json +7 -7
- package/node_modules/object-inspect/.eslintrc +0 -53
- package/node_modules/object-inspect/.nycrc +0 -13
- package/node_modules/object-inspect/example/all.js +0 -23
- package/node_modules/object-inspect/example/circular.js +0 -6
- package/node_modules/object-inspect/example/fn.js +0 -5
- package/node_modules/object-inspect/example/inspect.js +0 -10
- package/node_modules/object-inspect/test/bigint.js +0 -58
- package/node_modules/object-inspect/test/browser/dom.js +0 -15
- package/node_modules/object-inspect/test/circular.js +0 -16
- package/node_modules/object-inspect/test/deep.js +0 -12
- package/node_modules/object-inspect/test/element.js +0 -53
- package/node_modules/object-inspect/test/err.js +0 -48
- package/node_modules/object-inspect/test/fakes.js +0 -29
- package/node_modules/object-inspect/test/fn.js +0 -76
- package/node_modules/object-inspect/test/global.js +0 -17
- package/node_modules/object-inspect/test/has.js +0 -15
- package/node_modules/object-inspect/test/holes.js +0 -15
- package/node_modules/object-inspect/test/indent-option.js +0 -271
- package/node_modules/object-inspect/test/inspect.js +0 -139
- package/node_modules/object-inspect/test/lowbyte.js +0 -12
- package/node_modules/object-inspect/test/number.js +0 -58
- package/node_modules/object-inspect/test/quoteStyle.js +0 -26
- package/node_modules/object-inspect/test/toStringTag.js +0 -40
- package/node_modules/object-inspect/test/undef.js +0 -12
- package/node_modules/object-inspect/test/values.js +0 -261
- package/node_modules/object-inspect/test-core-js.js +0 -26
- package/node_modules/on-finished/HISTORY.md +0 -98
|
@@ -5,6 +5,7 @@ var qs = require('../');
|
|
|
5
5
|
var utils = require('../lib/utils');
|
|
6
6
|
var iconv = require('iconv-lite');
|
|
7
7
|
var SaferBuffer = require('safer-buffer').Buffer;
|
|
8
|
+
var url = require('url');
|
|
8
9
|
var hasSymbols = require('has-symbols');
|
|
9
10
|
var mockProperty = require('mock-property');
|
|
10
11
|
var emptyTestCases = require('./empty-keys-cases').emptyTestCases;
|
|
@@ -24,6 +25,28 @@ test('stringify()', function (t) {
|
|
|
24
25
|
st.end();
|
|
25
26
|
});
|
|
26
27
|
|
|
28
|
+
t.test('stringifies lone surrogates as U+FFFD', function (st) {
|
|
29
|
+
st.equal(qs.stringify({ a: '\uD800x' }), 'a=%EF%BF%BDx', 'lone high surrogate does not swallow the next character');
|
|
30
|
+
st.equal(qs.stringify({ a: '\uDC00x' }), 'a=%EF%BF%BDx', 'lone low surrogate does not swallow the next character');
|
|
31
|
+
st.equal(qs.stringify({ '\uD800': 'b' }), '%EF%BF%BD=b', 'lone surrogate in a key');
|
|
32
|
+
st.deepEqual(qs.parse(qs.stringify({ a: 'x\uD800y' })), { a: 'x\uFFFDy' }, 'parses back with U+FFFD in place of the lone surrogate');
|
|
33
|
+
st.equal(qs.stringify({ '\uDC00': 'b' }), '%EF%BF%BD=b', 'lone low surrogate in a key');
|
|
34
|
+
st.equal(qs.stringify({ a: { 'b\uD800': 'c' } }), 'a%5Bb%EF%BF%BD%5D=c', 'lone surrogate in a nested key does not swallow the closing bracket');
|
|
35
|
+
st.equal(qs.stringify({ a: '\uD800 x' }, { format: 'RFC1738' }), 'a=%EF%BF%BD+x', 'lone surrogate does not swallow a space in RFC1738');
|
|
36
|
+
st.equal(
|
|
37
|
+
qs.stringify({ 'a\uD800': { b: 'c' } }, { allowDots: true, encodeDotInKeys: true }),
|
|
38
|
+
'a%EF%BF%BD.b=c',
|
|
39
|
+
'lone surrogate does not swallow a dot separator'
|
|
40
|
+
);
|
|
41
|
+
st.equal(qs.stringify({ a: ['x\uD800', 'y'] }, { arrayFormat: 'comma' }), 'a=x%EF%BF%BD%2Cy', 'lone surrogate does not swallow a comma');
|
|
42
|
+
st.equal(
|
|
43
|
+
qs.stringify({ a: ['x\uD800', 'y'] }, { arrayFormat: 'comma', encodeValuesOnly: true }),
|
|
44
|
+
'a=x%EF%BF%BD,y',
|
|
45
|
+
'lone surrogate at the end of a comma-joined element encodes as U+FFFD'
|
|
46
|
+
);
|
|
47
|
+
st.end();
|
|
48
|
+
});
|
|
49
|
+
|
|
27
50
|
t.test('stringifies falsy values', function (st) {
|
|
28
51
|
st.equal(qs.stringify(undefined), '');
|
|
29
52
|
st.equal(qs.stringify(null), '');
|
|
@@ -212,63 +235,94 @@ test('stringify()', function (t) {
|
|
|
212
235
|
st.end();
|
|
213
236
|
});
|
|
214
237
|
|
|
215
|
-
|
|
216
|
-
// `stringify` percent-encodes the structural `.` separators that `allowDots` inserts between
|
|
217
|
-
// nested keys, not just the literal dots inside a key, which breaks the stringify -> parse
|
|
218
|
-
// round-trip. These assertions pin that behavior so it cannot change silently: the fix in
|
|
219
|
-
// https://github.com/ljharb/qs/pull/564 changes every output below, so landing that fix MUST
|
|
220
|
-
// update this test (that is the point — it forces the behavior change to be explicit).
|
|
221
|
-
t.test('[characterization] encodeDotInKeys currently over-encodes structural separator dots (pre-#564)', function (st) {
|
|
238
|
+
t.test('does not encode the structural separator dots between nested keys when encodeDotInKeys and allowDots are provided', function (st) {
|
|
222
239
|
st.equal(
|
|
223
|
-
qs.stringify(
|
|
224
|
-
|
|
225
|
-
|
|
240
|
+
qs.stringify(
|
|
241
|
+
{ a: { b: { c: 'd' } } },
|
|
242
|
+
{ allowDots: true, encodeDotInKeys: true }
|
|
243
|
+
),
|
|
244
|
+
'a.b.c=d',
|
|
245
|
+
'no key contains a literal dot, so encodeDotInKeys is a no-op on the separators'
|
|
226
246
|
);
|
|
227
247
|
st.equal(
|
|
228
|
-
qs.stringify(
|
|
229
|
-
|
|
230
|
-
|
|
248
|
+
qs.stringify(
|
|
249
|
+
{ a: { b: { c: { d: 'e' } } } },
|
|
250
|
+
{ allowDots: true, encodeDotInKeys: true }
|
|
251
|
+
),
|
|
252
|
+
'a.b.c.d=e',
|
|
253
|
+
'every nesting separator is preserved, not just the last one'
|
|
231
254
|
);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
255
|
+
|
|
256
|
+
st.deepEqual(
|
|
257
|
+
qs.parse(
|
|
258
|
+
qs.stringify({ a: { b: { c: 'd' } } }, { allowDots: true, encodeDotInKeys: true }),
|
|
259
|
+
{ allowDots: true, decodeDotInKeys: true }
|
|
260
|
+
),
|
|
261
|
+
{ a: { b: { c: 'd' } } },
|
|
262
|
+
'stringify -> parse round-trips a deeply nested object'
|
|
236
263
|
);
|
|
264
|
+
|
|
265
|
+
st.end();
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
t.test('encodeDotInKeys encodes only literal dots inside nested keys, never the structural separators, at any depth', function (st) {
|
|
237
269
|
st.equal(
|
|
238
270
|
qs.stringify({ a: { 'b.c': { d: 'e' } } }, { allowDots: true, encodeDotInKeys: true }),
|
|
239
|
-
'a%
|
|
240
|
-
'nested
|
|
271
|
+
'a.b%252Ec.d=e',
|
|
272
|
+
'a nested key with a literal dot and an object value encodes only its own dot'
|
|
273
|
+
);
|
|
274
|
+
st.equal(
|
|
275
|
+
qs.stringify({ 'a.b': { c: { d: 'e' } } }, { allowDots: true, encodeDotInKeys: true }),
|
|
276
|
+
'a%252Eb.c.d=e',
|
|
277
|
+
'a top-level dotted key stays encoded while deeper separators stay literal'
|
|
241
278
|
);
|
|
242
279
|
st.equal(
|
|
243
280
|
qs.stringify({ a: { b: { 'c.d': { e: 'f' } } } }, { allowDots: true, encodeDotInKeys: true }),
|
|
244
|
-
'a%
|
|
245
|
-
'deeply nested
|
|
281
|
+
'a.b.c%252Ed.e=f',
|
|
282
|
+
'a literal dot in a deeply nested key is encoded without touching the separators around it'
|
|
246
283
|
);
|
|
247
284
|
|
|
248
285
|
st.equal(
|
|
249
286
|
qs.stringify({ a: { b: [1, 2] } }, { allowDots: true, encodeDotInKeys: true }),
|
|
250
|
-
'a%
|
|
251
|
-
'
|
|
287
|
+
'a.b%5B0%5D=1&a.b%5B1%5D=2',
|
|
288
|
+
'separator dots are preserved for an array value nested under keys'
|
|
252
289
|
);
|
|
253
290
|
st.equal(
|
|
254
291
|
qs.stringify({ a: { 'b.c': [1, 2] } }, { allowDots: true, encodeDotInKeys: true }),
|
|
255
|
-
'a%
|
|
256
|
-
'
|
|
292
|
+
'a.b%252Ec%5B0%5D=1&a.b%252Ec%5B1%5D=2',
|
|
293
|
+
'a nested dotted key with an array value encodes only its own dot'
|
|
257
294
|
);
|
|
258
295
|
|
|
259
|
-
st.
|
|
260
|
-
qs.
|
|
261
|
-
|
|
262
|
-
|
|
296
|
+
st.deepEqual(
|
|
297
|
+
qs.parse(
|
|
298
|
+
qs.stringify({ a: { 'b.c': { d: 'e' } } }, { allowDots: true, encodeDotInKeys: true }),
|
|
299
|
+
{ allowDots: true, decodeDotInKeys: true }
|
|
300
|
+
),
|
|
301
|
+
{ a: { 'b.c': { d: 'e' } } },
|
|
302
|
+
'stringify -> parse round-trips a nested dotted key with an object value'
|
|
263
303
|
);
|
|
264
|
-
|
|
265
304
|
st.deepEqual(
|
|
266
305
|
qs.parse(
|
|
267
|
-
qs.stringify({ a: {
|
|
306
|
+
qs.stringify({ 'a.b': { c: { d: 'e' } } }, { allowDots: true, encodeDotInKeys: true }),
|
|
268
307
|
{ allowDots: true, decodeDotInKeys: true }
|
|
269
308
|
),
|
|
270
|
-
{ 'a.b': { c:
|
|
271
|
-
'
|
|
309
|
+
{ 'a.b': { c: { d: 'e' } } },
|
|
310
|
+
'stringify -> parse round-trips a top-level dotted key with deep nesting'
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
st.end();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
t.test('with allowDots false, encodeDotInKeys leaves nested-key dots literal, consistently for object and primitive values', function (st) {
|
|
317
|
+
st.equal(
|
|
318
|
+
qs.stringify({ a: { 'b.c': { d: 'e' } } }, { allowDots: false, encodeDotInKeys: true }),
|
|
319
|
+
'a%5Bb.c%5D%5Bd%5D=e',
|
|
320
|
+
'nested dotted key with an object value'
|
|
321
|
+
);
|
|
322
|
+
st.equal(
|
|
323
|
+
qs.stringify({ a: { 'b.c': 'e' } }, { allowDots: false, encodeDotInKeys: true }),
|
|
324
|
+
'a%5Bb.c%5D=e',
|
|
325
|
+
'nested dotted key with a primitive value matches the object-value case'
|
|
272
326
|
);
|
|
273
327
|
|
|
274
328
|
st.end();
|
|
@@ -394,6 +448,41 @@ test('stringify()', function (t) {
|
|
|
394
448
|
st.end();
|
|
395
449
|
});
|
|
396
450
|
|
|
451
|
+
t.test('ignores inherited array format names', function (st) {
|
|
452
|
+
var array = { a: ['b', 'c'] };
|
|
453
|
+
var indices = 'a%5B0%5D=b&a%5B1%5D=c';
|
|
454
|
+
var repeat = 'a=b&a=c';
|
|
455
|
+
|
|
456
|
+
st.equal(qs.stringify(array, { arrayFormat: 'unsupported' }), indices, 'unknown format falls back to `indices`');
|
|
457
|
+
|
|
458
|
+
var names = [
|
|
459
|
+
'constructor',
|
|
460
|
+
'toString',
|
|
461
|
+
'__proto__',
|
|
462
|
+
'valueOf',
|
|
463
|
+
'hasOwnProperty',
|
|
464
|
+
'isPrototypeOf',
|
|
465
|
+
'propertyIsEnumerable',
|
|
466
|
+
'toLocaleString'
|
|
467
|
+
];
|
|
468
|
+
for (var i = 0; i < names.length; i++) {
|
|
469
|
+
var name = names[i];
|
|
470
|
+
st.equal(qs.stringify(array, { arrayFormat: name }), indices, '`' + name + '` falls back to `indices`');
|
|
471
|
+
st.equal(
|
|
472
|
+
qs.stringify(array, { arrayFormat: name, indices: true }),
|
|
473
|
+
indices,
|
|
474
|
+
'`' + name + '` with `indices: true` falls back to `indices`'
|
|
475
|
+
);
|
|
476
|
+
st.equal(
|
|
477
|
+
qs.stringify(array, { arrayFormat: name, indices: false }),
|
|
478
|
+
repeat,
|
|
479
|
+
'`' + name + '` with `indices: false` falls back to `repeat`'
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
st.end();
|
|
484
|
+
});
|
|
485
|
+
|
|
397
486
|
t.test('`skipNulls` option', function (st) {
|
|
398
487
|
st.equal(
|
|
399
488
|
qs.stringify({ a: 'b', c: null }, { skipNulls: true }),
|
|
@@ -454,6 +543,24 @@ test('stringify()', function (t) {
|
|
|
454
543
|
st.end();
|
|
455
544
|
});
|
|
456
545
|
|
|
546
|
+
t.test('allowEmptyArrays keys that need no encoding', function (st) {
|
|
547
|
+
st.equal(qs.stringify({ foo: [] }, { allowEmptyArrays: true, format: 'RFC1738' }), 'foo[]', 'a top-level key in RFC1738');
|
|
548
|
+
st.equal(
|
|
549
|
+
qs.stringify({ a: { b: [] }, c: 'd e' }, { allowEmptyArrays: true, encodeValuesOnly: true }),
|
|
550
|
+
'a[b][]&c=d%20e',
|
|
551
|
+
'a nested key with encodeValuesOnly'
|
|
552
|
+
);
|
|
553
|
+
st.equal(qs.stringify({ a: { b: [] } }, { allowEmptyArrays: true, encode: false }), 'a[b][]', 'a nested key with encode: false');
|
|
554
|
+
st.equal(qs.stringify({ a: { b: [] } }, { allowEmptyArrays: true, allowDots: true }), 'a.b[]', 'a nested key with allowDots');
|
|
555
|
+
st.equal(
|
|
556
|
+
qs.stringify({ a: { b: [] } }, { allowEmptyArrays: true, allowDots: true, format: 'RFC1738' }),
|
|
557
|
+
'a.b[]',
|
|
558
|
+
'a nested key with allowDots in RFC1738'
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
st.end();
|
|
562
|
+
});
|
|
563
|
+
|
|
457
564
|
t.test('allowEmptyArrays + strictNullHandling', function (st) {
|
|
458
565
|
st.equal(
|
|
459
566
|
qs.stringify(
|
|
@@ -499,6 +606,62 @@ test('stringify()', function (t) {
|
|
|
499
606
|
st.end();
|
|
500
607
|
});
|
|
501
608
|
|
|
609
|
+
t.test('should encode the key of an empty array when allowEmptyArrays is set', function (st) {
|
|
610
|
+
st.equal(
|
|
611
|
+
qs.stringify({ 'a b': [] }, { allowEmptyArrays: true }),
|
|
612
|
+
'a%20b[]',
|
|
613
|
+
'default (RFC3986) percent-encodes the space in the key'
|
|
614
|
+
);
|
|
615
|
+
st.equal(
|
|
616
|
+
qs.stringify({ 'a b': [] }, { allowEmptyArrays: true, format: 'RFC1738' }),
|
|
617
|
+
'a+b[]',
|
|
618
|
+
'RFC1738 encodes the space in the key as a plus'
|
|
619
|
+
);
|
|
620
|
+
st.equal(
|
|
621
|
+
qs.stringify({ 'a b': [] }, { allowEmptyArrays: true, encodeValuesOnly: true }),
|
|
622
|
+
'a b[]',
|
|
623
|
+
'encodeValuesOnly leaves the key unencoded'
|
|
624
|
+
);
|
|
625
|
+
st.equal(
|
|
626
|
+
qs.stringify({ 'a b': [] }, { allowEmptyArrays: true, encode: false }),
|
|
627
|
+
'a b[]',
|
|
628
|
+
'encode: false leaves the key unencoded'
|
|
629
|
+
);
|
|
630
|
+
|
|
631
|
+
st.deepEqual(
|
|
632
|
+
qs.parse(qs.stringify({ 'a b': [], 'a&b=c': [] }, { allowEmptyArrays: true }), { allowEmptyArrays: true }),
|
|
633
|
+
{ 'a b': [], 'a&b=c': [] },
|
|
634
|
+
'the encoded keys round-trip back to the original, including `&` and `=`'
|
|
635
|
+
);
|
|
636
|
+
st.equal(
|
|
637
|
+
qs.stringify({ 'a b': ['x'] }, { allowEmptyArrays: true, arrayFormat: 'brackets' }),
|
|
638
|
+
'a%20b%5B%5D=x',
|
|
639
|
+
'the same key with a value encodes the key prefix identically'
|
|
640
|
+
);
|
|
641
|
+
st.equal(
|
|
642
|
+
qs.stringify({ a: { 'b c': [] } }, { allowEmptyArrays: true }),
|
|
643
|
+
'a%5Bb%20c%5D[]',
|
|
644
|
+
'a nested key prefix is encoded like the value path encodes it'
|
|
645
|
+
);
|
|
646
|
+
st.equal(
|
|
647
|
+
qs.stringify({ a: { b: [] } }, { allowEmptyArrays: true }),
|
|
648
|
+
'a%5Bb%5D[]',
|
|
649
|
+
'a nested key that needs no encoding still has its brackets encoded'
|
|
650
|
+
);
|
|
651
|
+
st.equal(
|
|
652
|
+
qs.stringify({ 'a.b': [] }, { allowEmptyArrays: true, allowDots: true, encodeDotInKeys: true }),
|
|
653
|
+
'a%252Eb[]',
|
|
654
|
+
'encodeDotInKeys double-encodes the dot, as on the value path'
|
|
655
|
+
);
|
|
656
|
+
st.deepEqual(
|
|
657
|
+
qs.parse('a%252Eb[]', { allowEmptyArrays: true, allowDots: true, decodeDotInKeys: true }),
|
|
658
|
+
{ 'a.b': [] },
|
|
659
|
+
'the encodeDotInKeys output round-trips'
|
|
660
|
+
);
|
|
661
|
+
|
|
662
|
+
st.end();
|
|
663
|
+
});
|
|
664
|
+
|
|
502
665
|
t.test('stringifies an array value with one item vs multiple items', function (st) {
|
|
503
666
|
st.test('non-array item', function (s2t) {
|
|
504
667
|
s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a=c');
|
|
@@ -569,6 +732,53 @@ test('stringify()', function (t) {
|
|
|
569
732
|
st.end();
|
|
570
733
|
});
|
|
571
734
|
|
|
735
|
+
t.test('encodes comma array values with the same encoder arguments as other values, with encodeValuesOnly', function (st) {
|
|
736
|
+
var commaValuesOnly = { arrayFormat: 'comma', encodeValuesOnly: true };
|
|
737
|
+
|
|
738
|
+
st.equal(
|
|
739
|
+
qs.stringify({ a: ['é', 'x'], b: 'é' }, utils.assign({ charset: 'iso-8859-1' }, commaValuesOnly)),
|
|
740
|
+
'a=%E9,x&b=%E9',
|
|
741
|
+
'respects charset iso-8859-1'
|
|
742
|
+
);
|
|
743
|
+
st.deepEqual(
|
|
744
|
+
qs.parse(qs.stringify({ a: ['é', 'x'] }, utils.assign({ charset: 'iso-8859-1' }, commaValuesOnly)), { charset: 'iso-8859-1', comma: true }),
|
|
745
|
+
{ a: ['é', 'x'] },
|
|
746
|
+
'round-trips in iso-8859-1'
|
|
747
|
+
);
|
|
748
|
+
st.equal(
|
|
749
|
+
qs.stringify({ a: ['☺'] }, utils.assign({ charset: 'iso-8859-1' }, commaValuesOnly)),
|
|
750
|
+
'a=%26%239786%3B',
|
|
751
|
+
'encodes unrepresentable chars as numeric entities in iso-8859-1'
|
|
752
|
+
);
|
|
753
|
+
st.equal(
|
|
754
|
+
qs.stringify({ a: ['(x)', 'y z'], b: '(x)' }, utils.assign({ format: qs.formats.RFC1738 }, commaValuesOnly)),
|
|
755
|
+
'a=(x),y+z&b=(x)',
|
|
756
|
+
'respects format RFC1738'
|
|
757
|
+
);
|
|
758
|
+
|
|
759
|
+
var calls = [];
|
|
760
|
+
st.equal(
|
|
761
|
+
qs.stringify({ a: ['b', 'c'] }, utils.assign({
|
|
762
|
+
encoder: function (str, defaultEncoder, charset, kind, format) {
|
|
763
|
+
calls[calls.length] = [str, typeof defaultEncoder, charset, kind, format];
|
|
764
|
+
return defaultEncoder(str, defaultEncoder, charset, kind, format).toUpperCase();
|
|
765
|
+
}
|
|
766
|
+
}, commaValuesOnly)),
|
|
767
|
+
'a=B,C',
|
|
768
|
+
'a custom encoder can call defaultEncoder'
|
|
769
|
+
);
|
|
770
|
+
st.deepEqual(
|
|
771
|
+
calls,
|
|
772
|
+
[
|
|
773
|
+
['b', 'function', 'utf-8', 'value', qs.formats.RFC3986],
|
|
774
|
+
['c', 'function', 'utf-8', 'value', qs.formats.RFC3986]
|
|
775
|
+
],
|
|
776
|
+
'a custom encoder receives defaultEncoder, charset, kind, and format'
|
|
777
|
+
);
|
|
778
|
+
|
|
779
|
+
st.end();
|
|
780
|
+
});
|
|
781
|
+
|
|
572
782
|
t.test('stringifies comma and empty non-array values', function (st) {
|
|
573
783
|
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'indices' }), 'a=,&b=&c=c,d%');
|
|
574
784
|
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'brackets' }), 'a=,&b=&c=c,d%');
|
|
@@ -865,6 +1075,112 @@ test('stringify()', function (t) {
|
|
|
865
1075
|
st.end();
|
|
866
1076
|
});
|
|
867
1077
|
|
|
1078
|
+
t.test('arrayFormat=comma: does not crash on entries with no callable `toString`', function (st) {
|
|
1079
|
+
var json = JSON.parse('{ "a": ["b", { "toString": "x" }, "c"] }');
|
|
1080
|
+
st.equal(qs.stringify(json, { arrayFormat: 'comma' }), 'a=b%2C%5Bobject%20Object%5D%2Cc', 'JSON own `toString`');
|
|
1081
|
+
st.equal(qs.stringify(json, { arrayFormat: 'comma', encode: false }), 'a=b,[object Object],c', 'with encode: false');
|
|
1082
|
+
st.equal(
|
|
1083
|
+
qs.stringify(json, { arrayFormat: 'comma', encodeValuesOnly: true }),
|
|
1084
|
+
'a=b,%5Bobject%20Object%5D,c',
|
|
1085
|
+
'with encodeValuesOnly'
|
|
1086
|
+
);
|
|
1087
|
+
st.equal(
|
|
1088
|
+
qs.stringify(JSON.parse('{ "a": [{ "toString": "x" }] }'), { arrayFormat: 'comma', commaRoundTrip: true }),
|
|
1089
|
+
'a%5B%5D=%5Bobject%20Object%5D',
|
|
1090
|
+
'with commaRoundTrip'
|
|
1091
|
+
);
|
|
1092
|
+
st.equal(
|
|
1093
|
+
qs.stringify(JSON.parse('{ "a": [{ "toString": "x" }] }'), { arrayFormat: 'comma' }),
|
|
1094
|
+
qs.stringify({ a: [{ b: 1 }] }, { arrayFormat: 'comma' }),
|
|
1095
|
+
'renders the same as a plain object entry'
|
|
1096
|
+
);
|
|
1097
|
+
|
|
1098
|
+
st.equal(
|
|
1099
|
+
qs.stringify(qs.parse('a[][b]=c', { plainObjects: true }), { arrayFormat: 'comma' }),
|
|
1100
|
+
'a=%5Bobject%20Object%5D',
|
|
1101
|
+
'null-prototype entry from `parse` with plainObjects'
|
|
1102
|
+
);
|
|
1103
|
+
st.equal(
|
|
1104
|
+
qs.stringify(qs.parse('a[][b]=c', { plainObjects: true }), { arrayFormat: 'comma', encodeValuesOnly: true }),
|
|
1105
|
+
'a=%5Bobject%20Object%5D',
|
|
1106
|
+
'null-prototype entry from `parse` with plainObjects, with encodeValuesOnly'
|
|
1107
|
+
);
|
|
1108
|
+
st.equal(
|
|
1109
|
+
qs.stringify(qs.parse('a[0][toString]=x', { allowPrototypes: true }), { arrayFormat: 'comma' }),
|
|
1110
|
+
'a=%5Bobject%20Object%5D',
|
|
1111
|
+
'own `toString` entry from `parse` with allowPrototypes'
|
|
1112
|
+
);
|
|
1113
|
+
|
|
1114
|
+
var nested = JSON.parse('{ "a": [[1, [{ "toString": "x" }]], "y"] }');
|
|
1115
|
+
st.equal(qs.stringify(nested, { arrayFormat: 'comma', encode: false }), 'a=1,[object Object],y', 'nested array');
|
|
1116
|
+
st.equal(
|
|
1117
|
+
qs.stringify(nested, { arrayFormat: 'comma', encodeValuesOnly: true }),
|
|
1118
|
+
'a=1%2C%5Bobject%20Object%5D,y',
|
|
1119
|
+
'nested array, with encodeValuesOnly'
|
|
1120
|
+
);
|
|
1121
|
+
st.equal(qs.stringify({ a: [[1, 2], 3] }, { arrayFormat: 'comma', encode: false }), 'a=1,2,3', 'nested array is still flattened');
|
|
1122
|
+
|
|
1123
|
+
var cyclic = [{ toString: 'x' }];
|
|
1124
|
+
cyclic[cyclic.length] = cyclic;
|
|
1125
|
+
st.equal(
|
|
1126
|
+
qs.stringify({ a: cyclic }, { arrayFormat: 'comma', encode: false }),
|
|
1127
|
+
'a=[object Object],[object Object],',
|
|
1128
|
+
'cyclic nested array joins its cycle as empty'
|
|
1129
|
+
);
|
|
1130
|
+
|
|
1131
|
+
var customJoin = [{ toString: 'x' }];
|
|
1132
|
+
customJoin.join = function () { return 'j'; };
|
|
1133
|
+
st.equal(qs.stringify({ a: [customJoin, 'y'] }, { arrayFormat: 'comma', encode: false }), 'a=j,y', 'own `join` is still used');
|
|
1134
|
+
|
|
1135
|
+
st.equal(
|
|
1136
|
+
qs.stringify({ a: [{ toString: 'x', valueOf: function () { return 7; } }] }, { arrayFormat: 'comma' }),
|
|
1137
|
+
'a=7',
|
|
1138
|
+
'primitive `valueOf` is still used'
|
|
1139
|
+
);
|
|
1140
|
+
st.equal(
|
|
1141
|
+
qs.stringify({ a: [{ toString: 'x', valueOf: function () { return null; } }] }, { arrayFormat: 'comma' }),
|
|
1142
|
+
'a=null',
|
|
1143
|
+
'null `valueOf` is still used'
|
|
1144
|
+
);
|
|
1145
|
+
st.equal(
|
|
1146
|
+
qs.stringify({ a: [{ toString: 'x', valueOf: function () { return {}; } }] }, { arrayFormat: 'comma' }),
|
|
1147
|
+
'a=%5Bobject%20Object%5D',
|
|
1148
|
+
'non-primitive `valueOf` falls back'
|
|
1149
|
+
);
|
|
1150
|
+
|
|
1151
|
+
st.equal(
|
|
1152
|
+
qs.stringify({ a: [{ toString: function () { return 't'; } }, new Date(0)] }, { arrayFormat: 'comma', encode: false }),
|
|
1153
|
+
'a=t,1970-01-01T00:00:00.000Z',
|
|
1154
|
+
'callable `toString` and dates are unaffected'
|
|
1155
|
+
);
|
|
1156
|
+
|
|
1157
|
+
st['throws'](
|
|
1158
|
+
function () {
|
|
1159
|
+
qs.stringify({ a: [{ toString: function () { throw new SyntaxError('mine'); } }] }, { arrayFormat: 'comma' });
|
|
1160
|
+
},
|
|
1161
|
+
SyntaxError,
|
|
1162
|
+
'a throwing `toString` still throws'
|
|
1163
|
+
);
|
|
1164
|
+
st['throws'](
|
|
1165
|
+
function () {
|
|
1166
|
+
qs.stringify({ a: [{ toString: 'x', valueOf: function () { throw new EvalError('mine'); } }] }, { arrayFormat: 'comma' });
|
|
1167
|
+
},
|
|
1168
|
+
EvalError,
|
|
1169
|
+
'a throwing `valueOf` still throws'
|
|
1170
|
+
);
|
|
1171
|
+
|
|
1172
|
+
st.end();
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
t.test('arrayFormat=comma: entries with `Symbol.toPrimitive` are unaffected', { skip: !hasSymbols() || typeof Symbol.toPrimitive !== 'symbol' }, function (st) {
|
|
1176
|
+
var entry = { toString: 'x' };
|
|
1177
|
+
entry[Symbol.toPrimitive] = function () { return 'p'; };
|
|
1178
|
+
st.equal(qs.stringify({ a: [entry] }, { arrayFormat: 'comma' }), 'a=p');
|
|
1179
|
+
st.equal(qs.stringify({ a: [entry] }, { arrayFormat: 'comma', encodeValuesOnly: true }), 'a=p');
|
|
1180
|
+
|
|
1181
|
+
st.end();
|
|
1182
|
+
});
|
|
1183
|
+
|
|
868
1184
|
t.test('stringifies a null object', { skip: !hasProto }, function (st) {
|
|
869
1185
|
st.equal(qs.stringify({ __proto__: null, a: 'b' }), 'a=b');
|
|
870
1186
|
st.end();
|
|
@@ -1095,6 +1411,53 @@ test('stringify()', function (t) {
|
|
|
1095
1411
|
st.end();
|
|
1096
1412
|
});
|
|
1097
1413
|
|
|
1414
|
+
t.test('applies sort to nested keys selected by filter=array', function (st) {
|
|
1415
|
+
var asc = function (a, b) { return a.localeCompare(b); };
|
|
1416
|
+
var desc = function (a, b) { return b.localeCompare(a); };
|
|
1417
|
+
|
|
1418
|
+
st.equal(
|
|
1419
|
+
qs.stringify({ a: { c: 1, b: 2 }, z: 3 }, { filter: ['z', 'a', 'c', 'b'], sort: asc, encode: false }),
|
|
1420
|
+
'a[b]=2&a[c]=1&z=3',
|
|
1421
|
+
'nested keys are sorted, not left in filter order'
|
|
1422
|
+
);
|
|
1423
|
+
st.equal(
|
|
1424
|
+
qs.stringify({ a: { c: 1, b: 2 }, z: 3 }, { filter: ['z', 'b', 'a', 'c'], sort: desc, encode: false }),
|
|
1425
|
+
'z=3&a[c]=1&a[b]=2',
|
|
1426
|
+
'nested keys follow a descending sort'
|
|
1427
|
+
);
|
|
1428
|
+
st.equal(
|
|
1429
|
+
qs.stringify({ a: [{ y: 1, x: 2 }] }, { filter: ['a', '0', 'y', 'x'], sort: asc, encode: false }),
|
|
1430
|
+
'a[0][x]=2&a[0][y]=1',
|
|
1431
|
+
'keys of objects nested in arrays are sorted'
|
|
1432
|
+
);
|
|
1433
|
+
st.equal(
|
|
1434
|
+
qs.stringify({ a: { c: 1, b: 2 }, z: 3 }, { filter: ['z', 'a', 'c', 'b'], encode: false }),
|
|
1435
|
+
'z=3&a[c]=1&a[b]=2',
|
|
1436
|
+
'without sort, keys keep filter order at every level'
|
|
1437
|
+
);
|
|
1438
|
+
|
|
1439
|
+
st.end();
|
|
1440
|
+
});
|
|
1441
|
+
|
|
1442
|
+
t.test('does not reorder the caller\'s filter array when sorting', function (st) {
|
|
1443
|
+
var filter = ['z', 'a', 'c', 'b'];
|
|
1444
|
+
var asc = function (a, b) { return a.localeCompare(b); };
|
|
1445
|
+
|
|
1446
|
+
st.equal(
|
|
1447
|
+
qs.stringify({ a: { c: 1, b: 2 }, z: 3 }, { filter: filter, sort: asc, encode: false }),
|
|
1448
|
+
'a[b]=2&a[c]=1&z=3',
|
|
1449
|
+
'keys are sorted at every level'
|
|
1450
|
+
);
|
|
1451
|
+
st.deepEqual(filter, ['z', 'a', 'c', 'b'], 'filter array is not mutated');
|
|
1452
|
+
st.equal(
|
|
1453
|
+
qs.stringify({ a: { c: 1, b: 2 }, z: 3 }, { filter: filter, encode: false }),
|
|
1454
|
+
'z=3&a[c]=1&a[b]=2',
|
|
1455
|
+
'reusing the filter without sort keeps its own order'
|
|
1456
|
+
);
|
|
1457
|
+
|
|
1458
|
+
st.end();
|
|
1459
|
+
});
|
|
1460
|
+
|
|
1098
1461
|
t.test('supports custom representations when filter=function', function (st) {
|
|
1099
1462
|
var calls = 0;
|
|
1100
1463
|
var obj = { a: 'b', c: 'd', e: { f: new Date(1257894000000) } };
|
|
@@ -1345,6 +1708,7 @@ test('stringify()', function (t) {
|
|
|
1345
1708
|
st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }, { format: qs.formats.RFC1738 }), 'a+b=a+b');
|
|
1346
1709
|
|
|
1347
1710
|
st.equal(qs.stringify({ 'foo(ref)': 'bar' }, { format: qs.formats.RFC1738 }), 'foo(ref)=bar');
|
|
1711
|
+
st.equal(qs.stringify({ 'a~*': '~*()' }, { format: qs.formats.RFC1738 }), 'a~%2A=~%2A()', 'leaves `~` unencoded and encodes `*`');
|
|
1348
1712
|
|
|
1349
1713
|
st.end();
|
|
1350
1714
|
});
|
|
@@ -1353,6 +1717,83 @@ test('stringify()', function (t) {
|
|
|
1353
1717
|
st.equal(qs.stringify({ a: 'b c' }, { format: qs.formats.RFC3986 }), 'a=b%20c');
|
|
1354
1718
|
st.equal(qs.stringify({ 'a b': 'c d' }, { format: qs.formats.RFC3986 }), 'a%20b=c%20d');
|
|
1355
1719
|
st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }, { format: qs.formats.RFC3986 }), 'a%20b=a%20b');
|
|
1720
|
+
st.equal(qs.stringify({ 'a~*': '~*()' }, { format: qs.formats.RFC3986 }), 'a~%2A=~%2A%28%29', 'leaves `~` unencoded, and encodes `*` and parens');
|
|
1721
|
+
|
|
1722
|
+
st.end();
|
|
1723
|
+
});
|
|
1724
|
+
|
|
1725
|
+
t.test('WHATWG serialization', function (st) {
|
|
1726
|
+
st.equal(qs.formats.WHATWG, 'WHATWG', 'is exported');
|
|
1727
|
+
st.equal(qs.stringify({ a: 'b c' }, { format: qs.formats.WHATWG }), 'a=b+c');
|
|
1728
|
+
st.equal(qs.stringify({ 'a b': 'c d' }, { format: qs.formats.WHATWG }), 'a+b=c+d');
|
|
1729
|
+
st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }, { format: qs.formats.WHATWG }), 'a+b=a+b');
|
|
1730
|
+
|
|
1731
|
+
st.equal(qs.stringify({ a: '~' }, { format: qs.formats.WHATWG }), 'a=%7E', 'encodes `~`');
|
|
1732
|
+
st.equal(qs.stringify({ a: '*' }, { format: qs.formats.WHATWG }), 'a=*', 'does not encode `*`');
|
|
1733
|
+
st.equal(qs.stringify({ 'foo(ref)': 'bar' }, { format: qs.formats.WHATWG }), 'foo%28ref%29=bar', 'encodes parentheses');
|
|
1734
|
+
st.equal(qs.stringify({ a: '-._' }, { format: qs.formats.WHATWG }), 'a=-._');
|
|
1735
|
+
st.equal(qs.stringify({ a: '+&=' }, { format: qs.formats.WHATWG }), 'a=%2B%26%3D');
|
|
1736
|
+
st.equal(qs.stringify({ a: { b: 'c d' } }, { format: qs.formats.WHATWG }), 'a%5Bb%5D=c+d');
|
|
1737
|
+
st.equal(qs.stringify({ a: 'b c' }, { format: qs.formats.WHATWG, encode: false }), 'a=b c', 'encode: false leaves the value alone');
|
|
1738
|
+
|
|
1739
|
+
st.equal(
|
|
1740
|
+
qs.stringify({ 'a~b*': { 'c d': '~* ' } }, { format: qs.formats.WHATWG, encodeValuesOnly: true }),
|
|
1741
|
+
'a~b*[c d]=%7E*+',
|
|
1742
|
+
'encodeValuesOnly: leaves keys alone'
|
|
1743
|
+
);
|
|
1744
|
+
st.equal(
|
|
1745
|
+
qs.stringify({ a: '~*\u00e9 ' }, { format: qs.formats.WHATWG, charset: 'iso-8859-1' }),
|
|
1746
|
+
'a=%7E*%E9+',
|
|
1747
|
+
'charset iso-8859-1'
|
|
1748
|
+
);
|
|
1749
|
+
st.equal(
|
|
1750
|
+
qs.stringify({ a: '~* ' }, {
|
|
1751
|
+
format: qs.formats.WHATWG,
|
|
1752
|
+
encoder: function (str, defaultEncoder, charset, type, format) {
|
|
1753
|
+
return defaultEncoder(str, defaultEncoder, charset, type, format);
|
|
1754
|
+
}
|
|
1755
|
+
}),
|
|
1756
|
+
'a=%7E*+',
|
|
1757
|
+
'an encoder wrapping the default encoder'
|
|
1758
|
+
);
|
|
1759
|
+
st.equal(
|
|
1760
|
+
qs.stringify({ a: ['~ x', '*'] }, { format: qs.formats.WHATWG, arrayFormat: 'comma' }),
|
|
1761
|
+
'a=%7E+x%2C*',
|
|
1762
|
+
'arrayFormat comma'
|
|
1763
|
+
);
|
|
1764
|
+
|
|
1765
|
+
st.end();
|
|
1766
|
+
});
|
|
1767
|
+
|
|
1768
|
+
var USP = typeof URLSearchParams === 'function' ? URLSearchParams : url.URLSearchParams;
|
|
1769
|
+
|
|
1770
|
+
t.test('WHATWG serialization matches URLSearchParams', { skip: typeof USP !== 'function' }, function (st) {
|
|
1771
|
+
var chars = [];
|
|
1772
|
+
for (var c = 0; c < 0x80; c++) {
|
|
1773
|
+
chars[chars.length] = String.fromCharCode(c);
|
|
1774
|
+
}
|
|
1775
|
+
chars.push('\u00e9', '\u20ac', '\uFFFF', '\uD83D\uDCA9', 'a b~c*d(e)f', '\uD800', '\uDC00', 'x\uDC00y');
|
|
1776
|
+
|
|
1777
|
+
for (var i = 0; i < chars.length; i++) {
|
|
1778
|
+
var key = {};
|
|
1779
|
+
key[chars[i]] = 'v';
|
|
1780
|
+
st.equal(
|
|
1781
|
+
qs.stringify({ k: chars[i] }, { format: qs.formats.WHATWG }),
|
|
1782
|
+
new USP([['k', chars[i]]]).toString(),
|
|
1783
|
+
'value ' + JSON.stringify(chars[i])
|
|
1784
|
+
);
|
|
1785
|
+
st.equal(
|
|
1786
|
+
qs.stringify(key, { format: qs.formats.WHATWG }),
|
|
1787
|
+
new USP([[chars[i], 'v']]).toString(),
|
|
1788
|
+
'key ' + JSON.stringify(chars[i])
|
|
1789
|
+
);
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
st.equal(
|
|
1793
|
+
qs.stringify({ a: { 'b~': 'c d' } }, { format: qs.formats.WHATWG }),
|
|
1794
|
+
new USP([['a[b~]', 'c d']]).toString(),
|
|
1795
|
+
'nested key'
|
|
1796
|
+
);
|
|
1356
1797
|
|
|
1357
1798
|
st.end();
|
|
1358
1799
|
});
|
|
@@ -1480,6 +1921,17 @@ test('stringify()', function (t) {
|
|
|
1480
1921
|
st.end();
|
|
1481
1922
|
});
|
|
1482
1923
|
|
|
1924
|
+
t.test('encodes a literal `+` as `%2B` in iso-8859-1 mode so it round-trips', function (st) {
|
|
1925
|
+
st.equal(qs.stringify({ a: 'b+c' }, { charset: 'iso-8859-1' }), 'a=b%2Bc', 'a `+` in a value is percent-encoded');
|
|
1926
|
+
st.equal(qs.stringify({ 'a+b': 'c' }, { charset: 'iso-8859-1' }), 'a%2Bb=c', 'a `+` in a key is percent-encoded');
|
|
1927
|
+
st.deepEqual(
|
|
1928
|
+
qs.parse(qs.stringify({ a: 'b+c' }, { charset: 'iso-8859-1' }), { charset: 'iso-8859-1' }),
|
|
1929
|
+
{ a: 'b+c' },
|
|
1930
|
+
'the `+` survives a round-trip instead of decoding to a space'
|
|
1931
|
+
);
|
|
1932
|
+
st.end();
|
|
1933
|
+
});
|
|
1934
|
+
|
|
1483
1935
|
t.test('respects an explicit charset of utf-8 (the default)', function (st) {
|
|
1484
1936
|
st.equal(qs.stringify({ a: 'æ' }, { charset: 'utf-8' }), 'a=%C3%A6');
|
|
1485
1937
|
st.end();
|