@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.
Files changed (167) hide show
  1. package/node_modules/@pairmesh/client/dist/build-info.generated.d.ts +12 -12
  2. package/node_modules/@pairmesh/client/dist/build-info.generated.js +6 -6
  3. package/node_modules/@pairmesh/client/dist/connectivity/relay/hosted-server.js +1 -1
  4. package/node_modules/@pairmesh/client/dist/session/schemas.d.ts +10 -10
  5. package/node_modules/@pairmesh/client/dist/session/schemas.d.ts.map +1 -1
  6. package/node_modules/@pairmesh/client/package.json +5 -5
  7. package/node_modules/@pairmesh/coordination/package.json +5 -5
  8. package/node_modules/@pairmesh/mcp/package.json +5 -5
  9. package/node_modules/@pairmesh/permissions/package.json +2 -2
  10. package/node_modules/@pairmesh/protocol/dist/action.d.ts +1 -1
  11. package/node_modules/@pairmesh/protocol/dist/inspection-execution.d.ts +1 -1
  12. package/node_modules/@pairmesh/protocol/dist/inspection-thread.d.ts +1 -1
  13. package/node_modules/@pairmesh/protocol/dist/inspection-thread.d.ts.map +1 -1
  14. package/node_modules/@pairmesh/protocol/dist/inspection.d.ts +2 -2
  15. package/node_modules/@pairmesh/protocol/dist/pairing.d.ts +1 -1
  16. package/node_modules/@pairmesh/protocol/dist/progress-event.d.ts +1 -1
  17. package/node_modules/@pairmesh/protocol/dist/progress-event.d.ts.map +1 -1
  18. package/node_modules/@pairmesh/protocol/package.json +2 -2
  19. package/node_modules/@pairmesh/shared/package.json +1 -1
  20. package/node_modules/body-parser/README.md +17 -13
  21. package/node_modules/body-parser/lib/read.js +74 -57
  22. package/node_modules/body-parser/lib/types/json.js +11 -11
  23. package/node_modules/body-parser/lib/types/urlencoded.js +5 -5
  24. package/node_modules/body-parser/lib/utils.js +0 -15
  25. package/node_modules/body-parser/package.json +7 -12
  26. package/node_modules/encodeurl/README.md +14 -0
  27. package/node_modules/encodeurl/index.js +9 -11
  28. package/node_modules/encodeurl/package.json +13 -6
  29. package/node_modules/jose/README.md +2 -2
  30. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +5 -4
  31. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -4
  32. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +5 -4
  33. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +5 -5
  34. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +5 -4
  35. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +5 -5
  36. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +5 -4
  37. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +5 -5
  38. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +5 -4
  39. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +6 -5
  40. package/node_modules/jose/dist/types/jws/general/sign.d.ts +9 -6
  41. package/node_modules/jose/dist/types/jws/general/verify.d.ts +7 -5
  42. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +10 -6
  43. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +1 -1
  44. package/node_modules/jose/dist/types/jwt/sign.d.ts +1 -1
  45. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +3 -1
  46. package/node_modules/jose/dist/types/jwt/verify.d.ts +6 -5
  47. package/node_modules/jose/dist/types/key/export.d.ts +1 -1
  48. package/node_modules/jose/dist/types/key/generate_secret.d.ts +1 -1
  49. package/node_modules/jose/dist/types/key/import.d.ts +2 -2
  50. package/node_modules/jose/dist/types/types.d.ts +173 -107
  51. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +3 -2
  52. package/node_modules/jose/dist/types/util/errors.d.ts +1 -1
  53. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +3 -2
  54. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +3 -3
  55. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +8 -8
  56. package/node_modules/jose/dist/webapi/jwks/local.js +2 -1
  57. package/node_modules/jose/dist/webapi/jwks/remote.js +6 -4
  58. package/node_modules/jose/dist/webapi/jws/general/sign.js +3 -3
  59. package/node_modules/jose/dist/webapi/jws/general/verify.js +5 -11
  60. package/node_modules/jose/dist/webapi/jwt/encrypt.js +6 -9
  61. package/node_modules/jose/dist/webapi/jwt/sign.js +2 -2
  62. package/node_modules/jose/dist/webapi/jwt/unsecured.js +3 -3
  63. package/node_modules/jose/dist/webapi/key/generate_secret.js +4 -4
  64. package/node_modules/jose/dist/webapi/lib/asn1.js +2 -2
  65. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +4 -4
  66. package/node_modules/jose/dist/webapi/lib/content_encryption.js +8 -8
  67. package/node_modules/jose/dist/webapi/lib/deflate.js +2 -1
  68. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +26 -23
  69. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +5 -5
  70. package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +2 -2
  71. package/node_modules/jose/dist/webapi/lib/jws_sign.js +11 -11
  72. package/node_modules/jose/dist/webapi/lib/jws_verify.js +19 -16
  73. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +48 -44
  74. package/node_modules/jose/dist/webapi/lib/key.js +6 -4
  75. package/node_modules/jose/dist/webapi/lib/key_management.js +17 -18
  76. package/node_modules/jose/dist/webapi/lib/validate.js +10 -10
  77. package/node_modules/jose/dist/webapi/util/decode_jwt.js +12 -12
  78. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -5
  79. package/node_modules/jose/package.json +1 -1
  80. package/node_modules/object-inspect/CHANGELOG.md +31 -0
  81. package/node_modules/object-inspect/index.js +326 -24
  82. package/node_modules/object-inspect/package.json +22 -13
  83. package/node_modules/object-inspect/readme.markdown +4 -1
  84. package/node_modules/object-inspect/stringWidth.js +68 -0
  85. package/node_modules/object-inspect/stringWidthRanges.js +38 -0
  86. package/node_modules/on-finished/index.js +14 -2
  87. package/node_modules/on-finished/package.json +11 -7
  88. package/node_modules/qs/.editorconfig +1 -1
  89. package/node_modules/qs/.github/THREAT_MODEL.md +4 -2
  90. package/node_modules/qs/CHANGELOG.md +103 -14
  91. package/node_modules/qs/README.md +90 -9
  92. package/node_modules/qs/dist/qs.js +19 -19
  93. package/node_modules/qs/eslint.config.mjs +61 -50
  94. package/node_modules/qs/lib/formats.js +7 -2
  95. package/node_modules/qs/lib/parse.js +121 -12
  96. package/node_modules/qs/lib/stringify.js +9 -7
  97. package/node_modules/qs/lib/utils.js +158 -15
  98. package/node_modules/qs/package.json +8 -8
  99. package/node_modules/qs/test/parse.js +509 -2
  100. package/node_modules/qs/test/stringify.js +485 -33
  101. package/node_modules/qs/test/utils.js +245 -3
  102. package/node_modules/router/HISTORY.md +67 -52
  103. package/node_modules/router/README.md +222 -2
  104. package/node_modules/router/index.d.ts +188 -0
  105. package/node_modules/router/index.js +86 -50
  106. package/node_modules/router/lib/layer.js +154 -47
  107. package/node_modules/router/lib/param.js +47 -0
  108. package/node_modules/router/lib/route.d.ts +118 -0
  109. package/node_modules/router/lib/route.js +14 -8
  110. package/node_modules/router/lib/symbols.js +4 -0
  111. package/node_modules/router/lib/tracing.js +173 -0
  112. package/node_modules/router/package.json +24 -9
  113. package/node_modules/ws/README.md +22 -31
  114. package/node_modules/ws/lib/buffer-util.js +13 -2
  115. package/node_modules/ws/lib/receiver.js +8 -0
  116. package/node_modules/ws/lib/sender.js +4 -1
  117. package/node_modules/ws/lib/websocket-server.js +3 -0
  118. package/node_modules/ws/lib/websocket.js +66 -16
  119. package/node_modules/ws/package.json +1 -1
  120. package/node_modules/zod/package.json +1 -1
  121. package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
  122. package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
  123. package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
  124. package/node_modules/zod/src/v4/core/compile.ts +9 -0
  125. package/node_modules/zod/src/v4/core/schemas.ts +35 -1
  126. package/node_modules/zod/src/v4/core/util.ts +13 -0
  127. package/node_modules/zod/src/v4/core/versions.ts +1 -1
  128. package/node_modules/zod/v4/core/compile.cjs +8 -0
  129. package/node_modules/zod/v4/core/compile.js +8 -0
  130. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  131. package/node_modules/zod/v4/core/schemas.d.cts +3 -1
  132. package/node_modules/zod/v4/core/schemas.d.ts +3 -1
  133. package/node_modules/zod/v4/core/schemas.js +30 -0
  134. package/node_modules/zod/v4/core/util.cjs +15 -0
  135. package/node_modules/zod/v4/core/util.d.cts +2 -0
  136. package/node_modules/zod/v4/core/util.d.ts +2 -0
  137. package/node_modules/zod/v4/core/util.js +14 -0
  138. package/node_modules/zod/v4/core/versions.cjs +1 -1
  139. package/node_modules/zod/v4/core/versions.js +1 -1
  140. package/package.json +7 -7
  141. package/node_modules/object-inspect/.eslintrc +0 -53
  142. package/node_modules/object-inspect/.nycrc +0 -13
  143. package/node_modules/object-inspect/example/all.js +0 -23
  144. package/node_modules/object-inspect/example/circular.js +0 -6
  145. package/node_modules/object-inspect/example/fn.js +0 -5
  146. package/node_modules/object-inspect/example/inspect.js +0 -10
  147. package/node_modules/object-inspect/test/bigint.js +0 -58
  148. package/node_modules/object-inspect/test/browser/dom.js +0 -15
  149. package/node_modules/object-inspect/test/circular.js +0 -16
  150. package/node_modules/object-inspect/test/deep.js +0 -12
  151. package/node_modules/object-inspect/test/element.js +0 -53
  152. package/node_modules/object-inspect/test/err.js +0 -48
  153. package/node_modules/object-inspect/test/fakes.js +0 -29
  154. package/node_modules/object-inspect/test/fn.js +0 -76
  155. package/node_modules/object-inspect/test/global.js +0 -17
  156. package/node_modules/object-inspect/test/has.js +0 -15
  157. package/node_modules/object-inspect/test/holes.js +0 -15
  158. package/node_modules/object-inspect/test/indent-option.js +0 -271
  159. package/node_modules/object-inspect/test/inspect.js +0 -139
  160. package/node_modules/object-inspect/test/lowbyte.js +0 -12
  161. package/node_modules/object-inspect/test/number.js +0 -58
  162. package/node_modules/object-inspect/test/quoteStyle.js +0 -26
  163. package/node_modules/object-inspect/test/toStringTag.js +0 -40
  164. package/node_modules/object-inspect/test/undef.js +0 -12
  165. package/node_modules/object-inspect/test/values.js +0 -261
  166. package/node_modules/object-inspect/test-core-js.js +0 -26
  167. package/node_modules/on-finished/HISTORY.md +0 -98
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var test = require('tape');
4
+ var forEach = require('for-each');
4
5
  var hasPropertyDescriptors = require('has-property-descriptors')();
5
6
  var iconv = require('iconv-lite');
6
7
  var mockProperty = require('mock-property');
@@ -62,10 +63,54 @@ test('parse()', function (t) {
62
63
  st.end();
63
64
  });
64
65
 
66
+ t.test('comma: `[]=` in a value does not wrap the value in an extra array', function (st) {
67
+ st.deepEqual(qs.parse('a[b]=1,2,3[]=x', { comma: true }), { a: { b: ['1', '2', '3[]=x'] } });
68
+ st.deepEqual(qs.parse('a[b]=1,2[]=3', { comma: true }), { a: { b: ['1', '2[]=3'] } });
69
+ st.deepEqual(qs.parse('a[]=1,2,3', { comma: true }), { a: [['1', '2', '3']] });
70
+ st.end();
71
+ });
72
+
65
73
  t.test('allows enabling dot notation', function (st) {
66
74
  st.deepEqual(qs.parse('a.b=c'), { 'a.b': 'c' });
67
75
  st.deepEqual(qs.parse('a.b=c', { allowDots: true }), { a: { b: 'c' } });
68
76
 
77
+ // a literal dot inside a bracket segment must not be rewritten by allowDots (#617)
78
+ st.deepEqual(
79
+ qs.parse('outer[a.b]=1', { allowDots: true }),
80
+ { outer: { 'a.b': '1' } },
81
+ 'a dot inside brackets stays part of the key when allowDots is true'
82
+ );
83
+ st.deepEqual(
84
+ qs.parse('outer[a.b]=1', { allowDots: true }),
85
+ qs.parse('outer[a.b]=1', { allowDots: false }),
86
+ 'allowDots does not change how a bracket segment containing a dot is parsed'
87
+ );
88
+ st.deepEqual(
89
+ qs.parse('a].b=c', { allowDots: true }),
90
+ { 'a]': { b: 'c' } },
91
+ 'a stray close bracket does not stop a later dot from being converted'
92
+ );
93
+ st.deepEqual(
94
+ qs.parse('a]].b[c.d]=e', { allowDots: true }),
95
+ { 'a]]': { b: { 'c.d': 'e' } } },
96
+ 'stray close brackets do not unbalance a later bracket segment'
97
+ );
98
+
99
+ st.end();
100
+ });
101
+
102
+ t.test('decode dot keys with case-insensitive percent escapes', function (st) {
103
+ var input = 'name%252eobj.first%252ename=John&name%252Eobj.last%252Ename=Doe';
104
+ st.deepEqual(
105
+ qs.parse(input, { decodeDotInKeys: true }),
106
+ { 'name.obj': { 'first.name': 'John', 'last.name': 'Doe' } },
107
+ 'lowercase and uppercase escapes decode in both parent and child keys'
108
+ );
109
+ st.deepEqual(
110
+ qs.parse(input, { allowDots: true, decodeDotInKeys: false }),
111
+ { 'name%2eobj': { 'first%2ename': 'John' }, 'name%2Eobj': { 'last%2Ename': 'Doe' } },
112
+ 'escaped dots remain unchanged when decoding is disabled'
113
+ );
69
114
  st.end();
70
115
  });
71
116
 
@@ -229,8 +274,34 @@ test('parse()', function (t) {
229
274
  st.end();
230
275
  });
231
276
 
277
+ t.test('ignores bracket-wrapped prototype keys when depth = 0 and allowPrototypes is false', function (st) {
278
+ st.deepEqual(qs.parse('[toString]=foo', { depth: 0 }), {}, 'the stored key is the bracket content');
279
+ st.deepEqual(qs.parse('[hasOwnProperty]=bar', { depth: 0 }), {});
280
+ st.deepEqual(qs.parse('%5BhasOwnProperty%5D=bar', { depth: 0 }), {}, 'percent-encoded brackets');
281
+ st.deepEqual(qs.parse('[toString]=foo&a=b', { depth: 0 }), { a: 'b' });
282
+ st.deepEqual(qs.parse('[toString]=foo', { depth: false }), {}, 'depth: false');
283
+ st.deepEqual(qs.parse('.toString=foo', { depth: 0, allowDots: true }), {}, 'a leading dot becomes a bracket group');
284
+ st.deepEqual(qs.parse('[a]=b&[toString]=foo', { depth: 0 }), { a: 'b' }, 'other bracket-wrapped keys still strip their brackets');
285
+ st.end();
286
+ });
287
+
232
288
  t.test('allows prototype keys when depth = 0 and allowPrototypes is true', function (st) {
233
289
  st.deepEqual(qs.parse('toString=foo', { depth: 0, allowPrototypes: true }), { toString: 'foo' });
290
+ st.deepEqual(qs.parse('[toString]=foo', { depth: 0, allowPrototypes: true }), { toString: 'foo' });
291
+ st.end();
292
+ });
293
+
294
+ t.test('keeps bracket-wrapped prototype keys when depth = 0 and plainObjects is true', function (st) {
295
+ var result = qs.parse('[toString]=foo', { depth: 0, plainObjects: true });
296
+ st.deepEqual(result, { __proto__: null, toString: 'foo' });
297
+ st.equal(Object.getPrototypeOf(result), null);
298
+ st.end();
299
+ });
300
+
301
+ t.test('strips one wrapping bracket pair from the key when depth = 0', function (st) {
302
+ st.deepEqual(qs.parse('[a]=b', { depth: 0 }), { a: 'b' });
303
+ st.deepEqual(qs.parse('[[toString]]=foo', { depth: 0 }), { '[toString]': 'foo' }, 'only the outer pair is stripped');
304
+ st.deepEqual(qs.parse('x[toString]=foo', { depth: 0 }), { 'x[toString]': 'foo' }, 'a key with a parent stays literal');
234
305
  st.end();
235
306
  });
236
307
 
@@ -360,6 +431,14 @@ test('parse()', function (t) {
360
431
  st.end();
361
432
  });
362
433
 
434
+ t.test('currently moves the key/value split to a later `]=` when the first `=` comes before any bracket group', function (st) {
435
+ characterizeParse(st, 'a=b[c]=d', undefined, { 'a=b': { c: 'd' } }, 'literal brackets after the first `=`');
436
+ characterizeParse(st, 'q=%5B1%5D=2', undefined, { 'q=': ['2'] }, 'encoded brackets collapse to an array');
437
+ characterizeParse(st, 'role=guest%5Bx%5Dy%5D=z', undefined, { 'role=guest': { x: 'z' } }, 'group opens after the first `=`, and the text after it is dropped');
438
+ characterizeParse(st, 'role=guest%5D=admin', undefined, { 'role=guest]': 'admin' }, 'encoded `]=` with no bracket group at all');
439
+ st.end();
440
+ });
441
+
363
442
  t.test('allows to specify array indices', function (st) {
364
443
  st.deepEqual(qs.parse('a[1]=c&a[0]=b&a[2]=d'), { a: ['b', 'c', 'd'] });
365
444
  st.deepEqual(qs.parse('a[1]=c&a[0]=b'), { a: ['b', 'c'] });
@@ -745,6 +824,38 @@ test('parse()', function (t) {
745
824
  st.end();
746
825
  });
747
826
 
827
+ t.test('does not mutate an object input', function (st) {
828
+ var arr = ['x'];
829
+ st.deepEqual(qs.parse({ a: arr, 'a[]': 'y' }), { a: ['x', 'y'] }, 'appends to a copy of an input array');
830
+ st.deepEqual(arr, ['x'], 'the input array is unchanged');
831
+
832
+ var nested = { b: ['x'] };
833
+ st.deepEqual(qs.parse({ a: nested, 'a[b][]': 'y' }), { a: { b: ['x', 'y'] } }, 'appends to a copy of a nested input array');
834
+ st.deepEqual(nested, { b: ['x'] }, 'the nested input array is unchanged');
835
+
836
+ var obj = { b: 'c' };
837
+ st.deepEqual(qs.parse({ a: obj, 'a[d]': 'e' }), { a: { b: 'c', d: 'e' } }, 'merges into a copy of an input object');
838
+ st.deepEqual(obj, { b: 'c' }, 'the input object is unchanged');
839
+
840
+ var sparse = { b: [1, undefined, 2] };
841
+ st.deepEqual(qs.parse({ a: sparse }), { a: { b: [1, 2] } }, 'compacts a copy of an input array');
842
+ st.deepEqual(sparse, { b: [1, undefined, 2] }, 'the input array is not compacted');
843
+
844
+ var nullProto = { __proto__: null, b: 'c' };
845
+ st.equal(Object.getPrototypeOf(qs.parse({ a: nullProto }).a), null, 'a null-prototype input object stays null-prototype');
846
+
847
+ var date = new Date(0);
848
+ st.equal(qs.parse({ a: date }).a, date, 'a non-plain object is not copied');
849
+
850
+ var cyclic = { b: 'c' };
851
+ cyclic.self = cyclic;
852
+ var result = qs.parse({ a: cyclic });
853
+ st.notEqual(result.a, cyclic, 'a cyclic input object is copied');
854
+ st.equal(result.a.self, result.a, 'the copy keeps the cycle');
855
+
856
+ st.end();
857
+ });
858
+
748
859
  t.test('does not blow up when Buffer global is missing', function (st) {
749
860
  var restore = mockProperty(global, 'Buffer', { 'delete': true });
750
861
 
@@ -962,6 +1073,38 @@ test('parse()', function (t) {
962
1073
  st.end();
963
1074
  });
964
1075
 
1076
+ t.test('strictMerge conflicts do not overwrite indexed values already at that path', function (st) {
1077
+ st.deepEqual(
1078
+ qs.parse('a[z]=o&a=p&a[y]=q&a[2]=keep&[a]=r'),
1079
+ { a: { 0: { z: 'o' }, 1: 'p', 2: 'keep', 3: 'r', y: 'q' } },
1080
+ 'an indexed key merged into the container is kept'
1081
+ );
1082
+
1083
+ st.deepEqual(
1084
+ qs.parse('a[z]=o&a=p&a[2]=keep&a[y]=q&[a]=r'),
1085
+ { a: { 0: { z: 'o' }, 1: 'p', 2: 'keep', 3: 'r', y: 'q' } },
1086
+ 'an indexed key that extended the container while it was an array is kept'
1087
+ );
1088
+
1089
+ st.end();
1090
+ });
1091
+
1092
+ t.test('strictMerge conflicts do not overwrite values once the container overflows', function (st) {
1093
+ st.deepEqual(
1094
+ qs.parse('a[z]=v0&a=v1&a[y]=v2&[a]=v3&[a]x=v4&a[2]=v5&[a]x1=v6', { arrayLimit: 2 }),
1095
+ { a: { 0: { z: 'v0' }, 1: 'v1', 2: ['v3', 'v5'], 3: 'v4', 4: 'v6', y: 'v2' } },
1096
+ 'a conflict appended after the container overflowed keeps every value'
1097
+ );
1098
+
1099
+ st.deepEqual(
1100
+ qs.parse('a[2]=v1&a=v5&a=v7&[a]x=v9', { parseArrays: false, arrayLimit: 1 }),
1101
+ { a: { 0: 'v5', 1: 'v7', 2: 'v1', 3: 'v9' } },
1102
+ 'an index the container already holds is not reused'
1103
+ );
1104
+
1105
+ st.end();
1106
+ });
1107
+
965
1108
  t.test('dunder proto is ignored', function (st) {
966
1109
  var payload = 'categories[__proto__]=login&categories[__proto__]&categories[length]=42';
967
1110
  var result = qs.parse(payload, { allowPrototypes: true });
@@ -1038,6 +1181,67 @@ test('parse()', function (t) {
1038
1181
  st.end();
1039
1182
  });
1040
1183
 
1184
+ var withOwnProto = function (value) {
1185
+ var obj = {};
1186
+ Object.defineProperty(obj, '__proto__', {
1187
+ configurable: true,
1188
+ enumerable: true,
1189
+ value: value,
1190
+ writable: true
1191
+ });
1192
+ return obj;
1193
+ };
1194
+ // node < 0.12 reads an own `__proto__` data property as `Object.prototype`, so it can not be copied by value
1195
+ var ownProtoIsReadable = withOwnProto(1).__proto__ === 1; // eslint-disable-line no-proto
1196
+
1197
+ t.test('object-valued input with only an own `__proto__` does not mutate sub-object [[Prototype]]', function (st) {
1198
+ // `JSON.parse` in node < 0.12 sets the [[Prototype]] instead of creating an own `__proto__`
1199
+ var out = qs.parse({ user: withOwnProto({ isAdmin: true }) });
1200
+
1201
+ st.equal(out.user.isAdmin, undefined, 'attacker-controlled inherited property is not exposed');
1202
+ st.equal(Object.getPrototypeOf(out.user), Object.prototype, 'sub-object [[Prototype]] is unchanged');
1203
+ st.equal(Object.prototype.isAdmin, undefined, 'Object.prototype is not polluted');
1204
+
1205
+ var sibling = withOwnProto({ isAdmin: true });
1206
+ sibling.name = 'alice';
1207
+ var withSibling = qs.parse({ user: sibling });
1208
+
1209
+ st.equal(withSibling.user.name, 'alice', 'sibling key is preserved');
1210
+ st.equal(withSibling.user.isAdmin, undefined, 'a sibling key does not hide an inherited property');
1211
+ st.equal(Object.getPrototypeOf(withSibling.user), Object.prototype, 'a sibling key does not change [[Prototype]]');
1212
+
1213
+ st.end();
1214
+ });
1215
+
1216
+ t.test('object-valued input keeps an own `__proto__` as a data property', { skip: !ownProtoIsReadable }, function (st) {
1217
+ var descriptor = function (value) {
1218
+ return {
1219
+ configurable: true,
1220
+ enumerable: true,
1221
+ value: value,
1222
+ writable: true
1223
+ };
1224
+ };
1225
+
1226
+ st.deepEqual(
1227
+ Object.getOwnPropertyDescriptor(qs.parse({ user: withOwnProto({ isAdmin: true }) }).user, '__proto__'),
1228
+ descriptor({ isAdmin: true }),
1229
+ 'an object value is stored as a data property'
1230
+ );
1231
+ st.deepEqual(
1232
+ Object.getOwnPropertyDescriptor(qs.parse({ user: withOwnProto('admin') }).user, '__proto__'),
1233
+ descriptor('admin'),
1234
+ 'a primitive value is stored as a data property'
1235
+ );
1236
+ st.deepEqual(
1237
+ Object.getOwnPropertyDescriptor(qs.parse({ 'user[name]': 'alice', user: withOwnProto({ isAdmin: true }) }).user, '__proto__'),
1238
+ descriptor({ isAdmin: true }),
1239
+ 'it survives a merge with a bracket key'
1240
+ );
1241
+
1242
+ st.end();
1243
+ });
1244
+
1041
1245
  t.test('can return null objects', { skip: !hasProto }, function (st) {
1042
1246
  var expected = {
1043
1247
  __proto__: null,
@@ -1061,6 +1265,19 @@ test('parse()', function (t) {
1061
1265
  st.end();
1062
1266
  });
1063
1267
 
1268
+ t.test('returns null objects for empty brackets when parseArrays is false', { skip: !hasProto }, function (st) {
1269
+ st.deepEqual(
1270
+ qs.parse('a[]=b', { parseArrays: false, plainObjects: true }),
1271
+ { __proto__: null, a: { __proto__: null, 0: 'b' } }
1272
+ );
1273
+ st.deepEqual(
1274
+ qs.parse('a[]=b&a[hasOwnProperty]=c', { parseArrays: false, plainObjects: true }),
1275
+ { __proto__: null, a: { __proto__: null, 0: 'b', hasOwnProperty: 'c' } },
1276
+ 'prototype keys land on a null object'
1277
+ );
1278
+ st.end();
1279
+ });
1280
+
1064
1281
  t.test('can parse with custom encoding', function (st) {
1065
1282
  st.deepEqual(qs.parse('%8c%a7=%91%e5%8d%e3%95%7b', {
1066
1283
  decoder: function (str) {
@@ -1153,6 +1370,31 @@ test('parse()', function (t) {
1153
1370
  st.end();
1154
1371
  });
1155
1372
 
1373
+ t.test('interprets numeric entities above U+FFFF as surrogate pairs', function (st) {
1374
+ var options = { charset: 'iso-8859-1', interpretNumericEntities: true };
1375
+ st.deepEqual(qs.parse('foo=%26%23128512%3B', options), { foo: '\uD83D\uDE00' }, 'U+1F600, which a browser submits as `&#128512;` from an iso-8859-1 form');
1376
+ st.deepEqual(qs.parse('foo=%26%2365536%3B', options), { foo: '\uD800\uDC00' }, 'U+10000');
1377
+ st.deepEqual(qs.parse('foo=%26%231114111%3B', options), { foo: '\uDBFF\uDFFF' }, 'U+10FFFF');
1378
+ st.deepEqual(qs.parse('foo=%26%2365535%3B', options), { foo: '\uFFFF' }, 'U+FFFF is still one code unit');
1379
+ st.end();
1380
+ });
1381
+
1382
+ t.test('interprets numeric entities in each value, but not in keys', function (st) {
1383
+ var options = { charset: 'iso-8859-1', interpretNumericEntities: true };
1384
+ st.deepEqual(qs.parse('a=' + urlEncodedNumSmiley + ',x', options), { a: '☺,x' }, 'a value with commas stays one string without `comma`');
1385
+ st.deepEqual(qs.parse('a' + urlEncodedNumSmiley + '=x', options), { 'a&#9786;': 'x' }, 'keys are not interpreted');
1386
+ st.deepEqual(qs.parse('a[]=' + urlEncodedNumSmiley + '&a[]=x', options), { a: ['☺', 'x'] }, 'bracket array values');
1387
+ st.deepEqual(qs.parse('a=' + urlEncodedNumSmiley + '&a=x', options), { a: ['☺', 'x'] }, 'repeated key values');
1388
+ st.deepEqual(qs.parse('a[b]=' + urlEncodedNumSmiley, options), { a: { b: '☺' } }, 'nested key values');
1389
+ st.deepEqual(
1390
+ qs.parse('utf8=%26%2310003%3B&a=' + urlEncodedNumSmiley, { charsetSentinel: true, interpretNumericEntities: true }),
1391
+ { a: '☺' },
1392
+ 'an iso-8859-1 charset sentinel enables interpretation'
1393
+ );
1394
+ st.deepEqual(qs.parse('a=' + urlEncodedNumSmiley + ',x', { charset: 'iso-8859-1', comma: true }), { a: ['&#9786;', 'x'] }, '`comma` splits without `interpretNumericEntities`');
1395
+ st.end();
1396
+ });
1397
+
1156
1398
  t.test('handles a custom decoder returning `null`, in the `iso-8859-1` charset, when `interpretNumericEntities`', function (st) {
1157
1399
  st.deepEqual(qs.parse('foo=&bar=' + urlEncodedNumSmiley, {
1158
1400
  charset: 'iso-8859-1',
@@ -1188,15 +1430,70 @@ test('parse()', function (t) {
1188
1430
  st.end();
1189
1431
  });
1190
1432
 
1191
- t.test('interpretNumericEntities with comma:true and iso charset does not crash', function (st) {
1433
+ t.test('interpretNumericEntities preserves comma arrays in iso charset', function (st) {
1192
1434
  st.deepEqual(
1193
1435
  qs.parse('b&a[]=1,' + urlEncodedNumSmiley, { comma: true, charset: 'iso-8859-1', interpretNumericEntities: true }),
1194
- { b: '', a: ['1,☺'] }
1436
+ { b: '', a: [['1', '☺']] }
1195
1437
  );
1196
1438
 
1197
1439
  st.end();
1198
1440
  });
1199
1441
 
1442
+ t.test('interprets numeric entities per comma-separated value', function (st) {
1443
+ var options = { comma: true, charset: 'iso-8859-1', interpretNumericEntities: true };
1444
+ st.deepEqual(qs.parse('a=b,c', options), { a: ['b', 'c'] });
1445
+ st.deepEqual(qs.parse('a=' + urlEncodedNumSmiley + ',%26%239786%3B', options), { a: ['☺', '☺'] });
1446
+ st.deepEqual(qs.parse('a=%26%2344%3B,b%2Cc', options), { a: [',', 'b,c'] });
1447
+ st.deepEqual(qs.parse('a=,b,', options), { a: ['', 'b', ''] });
1448
+ st.deepEqual(qs.parse('a=b,c&a=d,e', options), { a: ['b', 'c', 'd', 'e'] });
1449
+ st.deepEqual(qs.parse('a[]=b,c&a[]=d,e', options), { a: [['b', 'c'], ['d', 'e']] });
1450
+ st.deepEqual(qs.parse('a[0]=b,c', options), { a: [['b', 'c']] });
1451
+ st.deepEqual(qs.parse('utf8=%26%2310003%3B&a=b,' + urlEncodedNumSmiley, {
1452
+ comma: true,
1453
+ charsetSentinel: true,
1454
+ interpretNumericEntities: true
1455
+ }), { a: ['b', '☺'] });
1456
+ st.deepEqual(qs.parse('a=b,c,d', {
1457
+ comma: true,
1458
+ charset: 'iso-8859-1',
1459
+ interpretNumericEntities: true,
1460
+ arrayLimit: 2
1461
+ }), { a: { 0: 'b', 1: 'c', 2: 'd' } });
1462
+ st['throws'](function () {
1463
+ qs.parse('a=b,c,d', {
1464
+ comma: true,
1465
+ charset: 'iso-8859-1',
1466
+ interpretNumericEntities: true,
1467
+ arrayLimit: 2,
1468
+ throwOnLimitExceeded: true
1469
+ });
1470
+ }, RangeError);
1471
+ st.end();
1472
+ });
1473
+
1474
+ t.test('preserves falsy decoder results inside comma arrays', function (st) {
1475
+ st.deepEqual(qs.parse('a=null,0,false,' + urlEncodedNumSmiley, {
1476
+ comma: true,
1477
+ charset: 'iso-8859-1',
1478
+ interpretNumericEntities: true,
1479
+ decoder: function (str, defaultDecoder, charset, type) {
1480
+ if (type === 'value') {
1481
+ if (str === 'null') {
1482
+ return null;
1483
+ }
1484
+ if (str === '0') {
1485
+ return 0;
1486
+ }
1487
+ if (str === 'false') {
1488
+ return false;
1489
+ }
1490
+ }
1491
+ return defaultDecoder(str, defaultDecoder, charset, type);
1492
+ }
1493
+ }), { a: [null, 0, false, '☺'] });
1494
+ st.end();
1495
+ });
1496
+
1200
1497
  t.test('does not interpret %uXXXX syntax in iso-8859-1 mode', function (st) {
1201
1498
  st.deepEqual(qs.parse('%u263A=%u263A', { charset: 'iso-8859-1' }), { '%u263A': '%u263A' });
1202
1499
  st.end();
@@ -1320,6 +1617,41 @@ test('parse()', function (t) {
1320
1617
  sst.end();
1321
1618
  });
1322
1619
 
1620
+ st.test('zero and negative arrayLimit allow non-array values', function (sst) {
1621
+ forEach([0, -1], function (arrayLimit) {
1622
+ var options = { arrayLimit: arrayLimit, throwOnLimitExceeded: true };
1623
+ var label = 'arrayLimit ' + arrayLimit;
1624
+ sst.deepEqual(qs.parse('a=b&c[d]=e', options), { a: 'b', c: { d: 'e' } }, label + ': query string fields');
1625
+ sst.deepEqual(qs.parse('a=b', { arrayLimit: arrayLimit, throwOnLimitExceeded: true, comma: true }), { a: 'b' }, label + ': a value without commas when comma is enabled');
1626
+ sst.deepEqual(qs.parse({ a: 'b', 'c[d]': 'e' }, options), { a: 'b', c: { d: 'e' } }, label + ': object input fields');
1627
+ sst.deepEqual(qs.parse({ a: [] }, options), { a: [] }, label + ': an empty input array has no elements');
1628
+ sst.deepEqual(
1629
+ qs.parse('a=b&a=c', { arrayLimit: arrayLimit, throwOnLimitExceeded: true, duplicates: 'last' }),
1630
+ { a: 'c' },
1631
+ label + ': replacing a duplicate does not create an array'
1632
+ );
1633
+ sst.deepEqual(
1634
+ qs.parse('a[]=', { arrayLimit: arrayLimit, throwOnLimitExceeded: true, allowEmptyArrays: true }),
1635
+ { a: [] },
1636
+ label + ': an empty array has no elements to exceed the limit'
1637
+ );
1638
+ sst.deepEqual(qs.parse({ a: ['b'] }, options), { a: ['b'] }, label + ': an array value in object input is left as-is');
1639
+ sst.deepEqual(qs.parse({ 'a[b]': ['x'] }, options), { a: { b: ['x'] } }, label + ': an array value under a nested key in object input is left as-is');
1640
+ sst.deepEqual(qs.parse('a.b=c', { arrayLimit: arrayLimit, throwOnLimitExceeded: true, allowDots: true }), { a: { b: 'c' } }, label + ': dotted keys');
1641
+ sst.deepEqual(
1642
+ qs.parse('a=b&a=c', { arrayLimit: arrayLimit, throwOnLimitExceeded: true, duplicates: 'first' }),
1643
+ { a: 'b' },
1644
+ label + ': keeping the first duplicate does not create an array'
1645
+ );
1646
+ sst.deepEqual(
1647
+ qs.parse('a[]=b', { arrayLimit: arrayLimit, throwOnLimitExceeded: true, parseArrays: false }),
1648
+ { a: { 0: 'b' } },
1649
+ label + ': array syntax with parseArrays false does not create an array'
1650
+ );
1651
+ });
1652
+ sst.end();
1653
+ });
1654
+
1323
1655
  st.test('does not throw when at limit', function (sst) {
1324
1656
  // 3 elements = limit of 3, should not throw
1325
1657
  var result = qs.parse('a[]=1&a[]=2&a[]=3', { arrayLimit: 3, throwOnLimitExceeded: true });
@@ -1328,6 +1660,58 @@ test('parse()', function (t) {
1328
1660
  sst.end();
1329
1661
  });
1330
1662
 
1663
+ st.test('zero and negative arrayLimit', function (sst) {
1664
+ forEach([0, -1], function (arrayLimit) {
1665
+ var options = { arrayLimit: arrayLimit };
1666
+ var throwOptions = { arrayLimit: arrayLimit, throwOnLimitExceeded: true };
1667
+ var label = 'arrayLimit ' + arrayLimit;
1668
+
1669
+ sst.deepEqual(qs.parse('a=b&c[d]=e', options), { a: 'b', c: { d: 'e' } }, label + ': scalar and object fields are unaffected');
1670
+ sst.deepEqual(qs.parse('a[]=b', options), { a: { 0: 'b' } }, label + ': a bracket array becomes an object');
1671
+ sst.deepEqual(qs.parse('a[]=b&a[]=c', options), { a: { 0: 'b', 1: 'c' } }, label + ': a multi-element bracket array becomes an object');
1672
+ sst.deepEqual(qs.parse('a[0]=b', options), { a: { 0: 'b' } }, label + ': an indexed array becomes an object');
1673
+ sst.deepEqual(qs.parse('a=b&a=c', options), { a: { 0: 'b', 1: 'c' } }, label + ': combined duplicates become an object');
1674
+ sst.deepEqual(qs.parse('a[]=', options), { a: { 0: '' } }, label + ': an empty-string element still counts as an element');
1675
+ sst.deepEqual(qs.parse('a[]=', { arrayLimit: arrayLimit, allowEmptyArrays: true }), { a: [] }, label + ': an empty array has no elements');
1676
+ sst.deepEqual(qs.parse({ 'a[]': 'b' }, options), { a: { 0: 'b' } }, label + ': a bracket key in object input becomes an object');
1677
+ sst.deepEqual(qs.parse({ a: ['b'] }, options), { a: ['b'] }, label + ': an array value in object input is left as-is');
1678
+ sst.deepEqual(qs.parse({ a: [] }, options), { a: [] }, label + ': an empty array value in object input is left as-is');
1679
+
1680
+ var error = arrayLimit === 0
1681
+ ? new RangeError('Array limit exceeded. Only 0 elements allowed in an array.')
1682
+ : RangeError;
1683
+ sst['throws'](function () { qs.parse('a[]=b', throwOptions); }, error, label + ': throws on a bracket array');
1684
+ sst['throws'](function () { qs.parse('a[0]=b', throwOptions); }, error, label + ': throws on an indexed array');
1685
+ sst['throws'](function () { qs.parse('a=b&a=c', throwOptions); }, error, label + ': throws on combined duplicates');
1686
+ sst['throws'](function () { qs.parse('a[]=', throwOptions); }, error, label + ': throws on an empty-string element');
1687
+ sst['throws'](function () { qs.parse({ 'a[]': 'b' }, throwOptions); }, error, label + ': throws on a bracket key in object input');
1688
+ });
1689
+
1690
+ sst.end();
1691
+ });
1692
+
1693
+ st.test('zero and negative arrayLimit with comma', function (sst) {
1694
+ forEach([0, -1], function (arrayLimit) {
1695
+ var options = { arrayLimit: arrayLimit, comma: true };
1696
+ var throwOptions = { arrayLimit: arrayLimit, comma: true, throwOnLimitExceeded: true };
1697
+ var label = 'arrayLimit ' + arrayLimit;
1698
+
1699
+ sst.deepEqual(qs.parse('a=b', options), { a: 'b' }, label + ': a value without commas is unaffected');
1700
+ sst.deepEqual(qs.parse('a=b,c', options), { a: { 0: 'b', 1: 'c' } }, label + ': a comma value becomes an object');
1701
+ sst.deepEqual(qs.parse('a[]=b,c', options), { a: { 0: ['b', 'c'] } }, label + ': a bracket array holding a comma group becomes an object');
1702
+ sst.deepEqual(qs.parse('a[0]=b,c', options), { a: { 0: { 0: 'b', 1: 'c' } } }, label + ': an indexed comma group becomes an object');
1703
+
1704
+ var error = arrayLimit === 0
1705
+ ? new RangeError('Array limit exceeded. Only 0 elements allowed in an array.')
1706
+ : RangeError;
1707
+ sst['throws'](function () { qs.parse('a=b,c', throwOptions); }, error, label + ': throws on a comma value');
1708
+ sst['throws'](function () { qs.parse('a[]=b,c', throwOptions); }, error, label + ': throws on a comma group under `[]=`');
1709
+ sst['throws'](function () { qs.parse('a[0]=b,c', throwOptions); }, error, label + ': throws on an indexed comma group');
1710
+ });
1711
+
1712
+ sst.end();
1713
+ });
1714
+
1331
1715
  st.test('converts array to object if length is greater than limit', function (sst) {
1332
1716
  var result = qs.parse('a[1]=1&a[2]=2&a[3]=3&a[4]=4&a[5]=5&a[6]=6', { arrayLimit: 5 });
1333
1717
 
@@ -1463,12 +1847,113 @@ test('parse()', function (t) {
1463
1847
  sst.end();
1464
1848
  });
1465
1849
 
1850
+ st.test('counts the elements of a sparse indexed array on merge, not its holes', function (sst) {
1851
+ sst.deepEqual(qs.parse('a[]=new&a[19]=19&a[0]=0'), { a: ['new', '19', '0'] }, 'an array merged into a sparse array');
1852
+ sst.deepEqual(qs.parse('a[]=new&a[19]=19&a[0]=0', { throwOnLimitExceeded: true }), { a: ['new', '19', '0'] }, 'and it does not throw');
1853
+ sst.deepEqual(qs.parse('a[0]=w&a[19]=x&a[]=y'), { a: ['w', 'x', 'y'] }, 'a bracket value appended after a high index');
1854
+ sst.deepEqual(qs.parse('a[19]=x&a=y'), { a: ['x', 'y'] }, 'a scalar merged into a sparse array');
1855
+ sst.deepEqual(qs.parse('a[19]=x&a=y', { throwOnLimitExceeded: true }), { a: ['x', 'y'] }, 'and it does not throw');
1856
+
1857
+ sst.deepEqual(
1858
+ qs.parse('a[1]=x&a[]=y&a[]=z', { arrayLimit: 2 }),
1859
+ { a: { 0: 'y', 1: 'x', 2: 'z' } },
1860
+ 'more elements than arrayLimit still converts when the array has holes'
1861
+ );
1862
+ sst['throws'](
1863
+ function () { qs.parse('a[1]=x&a[]=y&a[]=z', { arrayLimit: 2, throwOnLimitExceeded: true }); },
1864
+ new RangeError('Array limit exceeded. Only 2 elements allowed in an array.'),
1865
+ 'and throws with throwOnLimitExceeded'
1866
+ );
1867
+
1868
+ sst.end();
1869
+ });
1870
+
1871
+ st.test('enforces arrayLimit when a strictMerge conflict appends to its container', function (sst) {
1872
+ var aliased = 'a[z]=o&a=p&a[y]=q&[a]=r';
1873
+ sst['throws'](
1874
+ function () { qs.parse(aliased, { arrayLimit: 2, throwOnLimitExceeded: true }); },
1875
+ new RangeError('Array limit exceeded. Only 2 elements allowed in an array.'),
1876
+ 'a third conflicting value throws once the container would exceed arrayLimit'
1877
+ );
1878
+ sst.deepEqual(
1879
+ qs.parse(aliased, { arrayLimit: 3, throwOnLimitExceeded: true }),
1880
+ { a: { 0: { z: 'o' }, 1: 'p', 2: 'r', y: 'q' } },
1881
+ 'appends while the container stays within arrayLimit'
1882
+ );
1883
+ sst.deepEqual(
1884
+ qs.parse(aliased, { arrayLimit: 2 }),
1885
+ { a: { 0: { z: 'o' }, 1: 'p', 2: 'r', y: 'q' } },
1886
+ 'appends without throwing when throwOnLimitExceeded is not set'
1887
+ );
1888
+
1889
+ sst.end();
1890
+ });
1891
+
1892
+ st.test('enforces arrayLimit when differently spelled keys collide', function (sst) {
1893
+ sst['throws'](
1894
+ function () { qs.parse('[a]=x&a=y', { arrayLimit: 1, throwOnLimitExceeded: true }); },
1895
+ new RangeError('Array limit exceeded. Only 1 element allowed in an array.'),
1896
+ 'two primitives throw, as `a=x&a=y` does'
1897
+ );
1898
+ sst['throws'](
1899
+ function () { qs.parse('a[b]=x&a=y', { arrayLimit: 1, throwOnLimitExceeded: true }); },
1900
+ new RangeError('Array limit exceeded. Only 1 element allowed in an array.'),
1901
+ 'an object and a primitive throw under strictMerge'
1902
+ );
1903
+ sst.deepEqual(
1904
+ qs.parse('[a]=x&a=y', { arrayLimit: 1 }),
1905
+ { a: { 0: 'x', 1: 'y' } },
1906
+ 'without throwOnLimitExceeded, two primitives convert to an object, as `a=x&a=y` does'
1907
+ );
1908
+ sst.deepEqual(
1909
+ qs.parse('a[b]=x&a=y', { arrayLimit: 1 }),
1910
+ { a: { 0: { b: 'x' }, 1: 'y' } },
1911
+ 'and so do an object and a primitive'
1912
+ );
1913
+ sst.deepEqual(
1914
+ qs.parse('a[b]=x&a=y', { arrayLimit: 2, throwOnLimitExceeded: true }),
1915
+ { a: [{ b: 'x' }, 'y'] },
1916
+ 'a collision within arrayLimit is still an array'
1917
+ );
1918
+
1919
+ sst.end();
1920
+ });
1921
+
1466
1922
  st.test('does not throw when cumulative comma combine stays within arrayLimit', function (sst) {
1467
1923
  var result = qs.parse('a=1,2,3&a=4', { comma: true, arrayLimit: 5, throwOnLimitExceeded: true });
1468
1924
  sst.deepEqual(result, { a: ['1', '2', '3', '4'] }, 'combined array within limit is preserved');
1469
1925
  sst.end();
1470
1926
  });
1471
1927
 
1928
+ st.test('throws when a comma array at arrayLimit is combined with one more value', function (sst) {
1929
+ var error = new RangeError('Array limit exceeded. Only 2 elements allowed in an array.');
1930
+ sst['throws'](
1931
+ function () { qs.parse('a=x,y&a=z', { comma: true, arrayLimit: 2, throwOnLimitExceeded: true }); },
1932
+ error,
1933
+ 'a plain value appended to a full comma array'
1934
+ );
1935
+ sst['throws'](
1936
+ function () { qs.parse('a=x&a=y,z', { comma: true, arrayLimit: 2, throwOnLimitExceeded: true }); },
1937
+ error,
1938
+ 'a comma value appended to a plain value'
1939
+ );
1940
+ sst.end();
1941
+ });
1942
+
1943
+ st.test('does not throw when a duplicate of a full comma array is discarded or replaces it', function (sst) {
1944
+ sst.deepEqual(
1945
+ qs.parse('a=x,y&a=z', { comma: true, arrayLimit: 2, throwOnLimitExceeded: true, duplicates: 'first' }),
1946
+ { a: ['x', 'y'] },
1947
+ 'duplicates: first keeps the full array'
1948
+ );
1949
+ sst.deepEqual(
1950
+ qs.parse('a=x,y&a=z', { comma: true, arrayLimit: 2, throwOnLimitExceeded: true, duplicates: 'last' }),
1951
+ { a: 'z' },
1952
+ 'duplicates: last replaces the full array'
1953
+ );
1954
+ sst.end();
1955
+ });
1956
+
1472
1957
  st.test('silently combines to an overflow object when throwOnLimitExceeded is not set', function (sst) {
1473
1958
  var result = qs.parse('a=1,2,3&a=4,5,6', { comma: true, arrayLimit: 5 });
1474
1959
  sst.deepEqual(result, { a: { 0: '1', 1: '2', 2: '3', 3: '4', 4: '5', 5: '6' } }, 'converts to object without throwing');
@@ -1807,6 +2292,28 @@ test('`duplicates` option', function (t) {
1807
2292
  st.end();
1808
2293
  });
1809
2294
 
2295
+ t.test('`[]=` in a value does not force combining', function (st) {
2296
+ st.deepEqual(
2297
+ qs.parse('a[b]=1&a[b]=2[]=3', { duplicates: 'last' }),
2298
+ { a: { b: '2[]=3' } },
2299
+ 'duplicates last: `[]=` in the value is not a bracketed key'
2300
+ );
2301
+
2302
+ st.deepEqual(
2303
+ qs.parse('a[b]=1&a[b]=2[]=3', { duplicates: 'first' }),
2304
+ { a: { b: '1' } },
2305
+ 'duplicates first: `[]=` in the value is not a bracketed key'
2306
+ );
2307
+
2308
+ st.deepEqual(
2309
+ qs.parse('a[b]=1&a[b]=2[]=3', { duplicates: 'combine' }),
2310
+ { a: { b: ['1', '2[]=3'] } },
2311
+ 'duplicates combine: still combines'
2312
+ );
2313
+
2314
+ st.end();
2315
+ });
2316
+
1810
2317
  t.end();
1811
2318
  });
1812
2319