cdk-common 2.0.775 → 2.0.776

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.
@@ -6,6 +6,7 @@ var utils = require('../lib/utils');
6
6
  var iconv = require('iconv-lite');
7
7
  var SaferBuffer = require('safer-buffer').Buffer;
8
8
  var hasSymbols = require('has-symbols');
9
+ var mockProperty = require('mock-property');
9
10
  var emptyTestCases = require('./empty-keys-cases').emptyTestCases;
10
11
  var hasBigInt = typeof BigInt === 'function';
11
12
 
@@ -64,6 +65,128 @@ test('stringify()', function (t) {
64
65
  st.end();
65
66
  });
66
67
 
68
+ t.test('encodes dot in key of object when encodeDotInKeys and allowDots is provided', function (st) {
69
+ st.equal(
70
+ qs.stringify(
71
+ { 'name.obj': { first: 'John', last: 'Doe' } },
72
+ { allowDots: false, encodeDotInKeys: false }
73
+ ),
74
+ 'name.obj%5Bfirst%5D=John&name.obj%5Blast%5D=Doe',
75
+ 'with allowDots false and encodeDotInKeys false'
76
+ );
77
+ st.equal(
78
+ qs.stringify(
79
+ { 'name.obj': { first: 'John', last: 'Doe' } },
80
+ { allowDots: true, encodeDotInKeys: false }
81
+ ),
82
+ 'name.obj.first=John&name.obj.last=Doe',
83
+ 'with allowDots true and encodeDotInKeys false'
84
+ );
85
+ st.equal(
86
+ qs.stringify(
87
+ { 'name.obj': { first: 'John', last: 'Doe' } },
88
+ { allowDots: false, encodeDotInKeys: true }
89
+ ),
90
+ 'name%252Eobj%5Bfirst%5D=John&name%252Eobj%5Blast%5D=Doe',
91
+ 'with allowDots false and encodeDotInKeys true'
92
+ );
93
+ st.equal(
94
+ qs.stringify(
95
+ { 'name.obj': { first: 'John', last: 'Doe' } },
96
+ { allowDots: true, encodeDotInKeys: true }
97
+ ),
98
+ 'name%252Eobj.first=John&name%252Eobj.last=Doe',
99
+ 'with allowDots true and encodeDotInKeys true'
100
+ );
101
+
102
+ st.equal(
103
+ qs.stringify(
104
+ { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
105
+ { allowDots: false, encodeDotInKeys: false }
106
+ ),
107
+ 'name.obj.subobject%5Bfirst.godly.name%5D=John&name.obj.subobject%5Blast%5D=Doe',
108
+ 'with allowDots false and encodeDotInKeys false'
109
+ );
110
+ st.equal(
111
+ qs.stringify(
112
+ { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
113
+ { allowDots: true, encodeDotInKeys: false }
114
+ ),
115
+ 'name.obj.subobject.first.godly.name=John&name.obj.subobject.last=Doe',
116
+ 'with allowDots false and encodeDotInKeys false'
117
+ );
118
+ st.equal(
119
+ qs.stringify(
120
+ { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
121
+ { allowDots: false, encodeDotInKeys: true }
122
+ ),
123
+ 'name%252Eobj%252Esubobject%5Bfirst.godly.name%5D=John&name%252Eobj%252Esubobject%5Blast%5D=Doe',
124
+ 'with allowDots false and encodeDotInKeys true'
125
+ );
126
+ st.equal(
127
+ qs.stringify(
128
+ { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
129
+ { allowDots: true, encodeDotInKeys: true }
130
+ ),
131
+ 'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',
132
+ 'with allowDots true and encodeDotInKeys true'
133
+ );
134
+
135
+ st.end();
136
+ });
137
+
138
+ t.test('should encode dot in key of object, and automatically set allowDots to `true` when encodeDotInKeys is true and allowDots in undefined', function (st) {
139
+ st.equal(
140
+ qs.stringify(
141
+ { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
142
+ { encodeDotInKeys: true }
143
+ ),
144
+ 'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',
145
+ 'with allowDots undefined and encodeDotInKeys true'
146
+ );
147
+ st.end();
148
+ });
149
+
150
+ t.test('should encode dot in key of object when encodeDotInKeys and allowDots is provided, and nothing else when encodeValuesOnly is provided', function (st) {
151
+ st.equal(
152
+ qs.stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, {
153
+ encodeDotInKeys: true, allowDots: true, encodeValuesOnly: true
154
+ }),
155
+ 'name%2Eobj.first=John&name%2Eobj.last=Doe'
156
+ );
157
+
158
+ st.equal(
159
+ qs.stringify({ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } }, { allowDots: true, encodeDotInKeys: true, encodeValuesOnly: true }),
160
+ 'name%2Eobj%2Esubobject.first%2Egodly%2Ename=John&name%2Eobj%2Esubobject.last=Doe'
161
+ );
162
+
163
+ st.end();
164
+ });
165
+
166
+ t.test('should throw when encodeDotInKeys is not of type boolean', function (st) {
167
+ st['throws'](
168
+ function () { qs.stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 'foobar' }); },
169
+ TypeError
170
+ );
171
+
172
+ st['throws'](
173
+ function () { qs.stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 0 }); },
174
+ TypeError
175
+ );
176
+
177
+ st['throws'](
178
+ function () { qs.stringify({ a: [], b: 'zz' }, { encodeDotInKeys: NaN }); },
179
+ TypeError
180
+ );
181
+
182
+ st['throws'](
183
+ function () { qs.stringify({ a: [], b: 'zz' }, { encodeDotInKeys: null }); },
184
+ TypeError
185
+ );
186
+
187
+ st.end();
188
+ });
189
+
67
190
  t.test('adds query prefix', function (st) {
68
191
  st.equal(qs.stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b');
69
192
  st.end();
@@ -87,7 +210,7 @@ test('stringify()', function (t) {
87
210
  st.end();
88
211
  });
89
212
 
90
- t.test('stringifies a nested object with dots notation', function (st) {
213
+ t.test('`allowDots` option: stringifies a nested object with dots notation', function (st) {
91
214
  st.equal(qs.stringify({ a: { b: 'c' } }, { allowDots: true }), 'a.b=c');
92
215
  st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }, { allowDots: true }), 'a.b.c.d=e');
93
216
  st.end();
@@ -109,6 +232,11 @@ test('stringify()', function (t) {
109
232
  'a=b%2Cc%2Cd',
110
233
  'comma => comma'
111
234
  );
235
+ st.equal(
236
+ qs.stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma', commaRoundTrip: true }),
237
+ 'a=b%2Cc%2Cd',
238
+ 'comma round trip => comma'
239
+ );
112
240
  st.equal(
113
241
  qs.stringify({ a: ['b', 'c', 'd'] }),
114
242
  'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',
@@ -117,18 +245,63 @@ test('stringify()', function (t) {
117
245
  st.end();
118
246
  });
119
247
 
120
- t.test('omits nulls when asked', function (st) {
121
- st.equal(qs.stringify({ a: 'b', c: null }, { skipNulls: true }), 'a=b');
122
- st.end();
123
- });
248
+ t.test('`skipNulls` option', function (st) {
249
+ st.equal(
250
+ qs.stringify({ a: 'b', c: null }, { skipNulls: true }),
251
+ 'a=b',
252
+ 'omits nulls when asked'
253
+ );
254
+
255
+ st.equal(
256
+ qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true }),
257
+ 'a%5Bb%5D=c',
258
+ 'omits nested nulls when asked'
259
+ );
124
260
 
125
- t.test('omits nested nulls when asked', function (st) {
126
- st.equal(qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true }), 'a%5Bb%5D=c');
127
261
  st.end();
128
262
  });
129
263
 
130
264
  t.test('omits array indices when asked', function (st) {
131
265
  st.equal(qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false }), 'a=b&a=c&a=d');
266
+
267
+ st.end();
268
+ });
269
+
270
+ t.test('omits object key/value pair when value is empty array', function (st) {
271
+ st.equal(qs.stringify({ a: [], b: 'zz' }), 'b=zz');
272
+
273
+ st.end();
274
+ });
275
+
276
+ t.test('should not omit object key/value pair when value is empty array and when asked', function (st) {
277
+ st.equal(qs.stringify({ a: [], b: 'zz' }), 'b=zz');
278
+ st.equal(qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: false }), 'b=zz');
279
+ st.equal(qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: true }), 'a[]&b=zz');
280
+
281
+ st.end();
282
+ });
283
+
284
+ t.test('should throw when allowEmptyArrays is not of type boolean', function (st) {
285
+ st['throws'](
286
+ function () { qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 'foobar' }); },
287
+ TypeError
288
+ );
289
+
290
+ st['throws'](
291
+ function () { qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 0 }); },
292
+ TypeError
293
+ );
294
+
295
+ st['throws'](
296
+ function () { qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: NaN }); },
297
+ TypeError
298
+ );
299
+
300
+ st['throws'](
301
+ function () { qs.stringify({ a: [], b: 'zz' }, { allowEmptyArrays: null }); },
302
+ TypeError
303
+ );
304
+
132
305
  st.end();
133
306
  });
134
307
 
@@ -156,6 +329,7 @@ test('stringify()', function (t) {
156
329
  s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c&a[1]=d');
157
330
  s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c&a[]=d');
158
331
  s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c,d');
332
+ s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true }), 'a=c,d');
159
333
  s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true }), 'a[0]=c&a[1]=d');
160
334
 
161
335
  s2t.end();
@@ -165,6 +339,9 @@ test('stringify()', function (t) {
165
339
  s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c%2Cd,e');
166
340
  s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma' }), 'a=c%2Cd%2Ce');
167
341
 
342
+ s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true }), 'a=c%2Cd,e');
343
+ s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma', commaRoundTrip: true }), 'a=c%2Cd%2Ce');
344
+
168
345
  s2t.end();
169
346
  });
170
347
 
@@ -255,36 +432,44 @@ test('stringify()', function (t) {
255
432
 
256
433
  t.test('stringifies an object inside an array', function (st) {
257
434
  st.equal(
258
- qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices' }),
259
- 'a%5B0%5D%5Bb%5D=c', // a[0][b]=c
260
- 'indices => brackets'
435
+ qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices', encodeValuesOnly: true }),
436
+ 'a[0][b]=c',
437
+ 'indices => indices'
438
+ );
439
+ st.equal(
440
+ qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'repeat', encodeValuesOnly: true }),
441
+ 'a[b]=c',
442
+ 'repeat => repeat'
261
443
  );
262
444
  st.equal(
263
- qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets' }),
264
- 'a%5B%5D%5Bb%5D=c', // a[][b]=c
445
+ qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets', encodeValuesOnly: true }),
446
+ 'a[][b]=c',
265
447
  'brackets => brackets'
266
448
  );
267
449
  st.equal(
268
- qs.stringify({ a: [{ b: 'c' }] }),
269
- 'a%5B0%5D%5Bb%5D=c',
450
+ qs.stringify({ a: [{ b: 'c' }] }, { encodeValuesOnly: true }),
451
+ 'a[0][b]=c',
270
452
  'default => indices'
271
453
  );
272
454
 
273
455
  st.equal(
274
- qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices' }),
275
- 'a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1',
456
+ qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices', encodeValuesOnly: true }),
457
+ 'a[0][b][c][0]=1',
276
458
  'indices => indices'
277
459
  );
278
-
279
460
  st.equal(
280
- qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets' }),
281
- 'a%5B%5D%5Bb%5D%5Bc%5D%5B%5D=1',
461
+ qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'repeat', encodeValuesOnly: true }),
462
+ 'a[b][c]=1',
463
+ 'repeat => repeat'
464
+ );
465
+ st.equal(
466
+ qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets', encodeValuesOnly: true }),
467
+ 'a[][b][c][]=1',
282
468
  'brackets => brackets'
283
469
  );
284
-
285
470
  st.equal(
286
- qs.stringify({ a: [{ b: { c: [1] } }] }),
287
- 'a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1',
471
+ qs.stringify({ a: [{ b: { c: [1] } }] }, { encodeValuesOnly: true }),
472
+ 'a[0][b][c][0]=1',
288
473
  'default => indices'
289
474
  );
290
475
 
@@ -386,17 +571,17 @@ test('stringify()', function (t) {
386
571
  st.end();
387
572
  });
388
573
 
389
- t.test('uses indices notation for arrays when no arrayFormat=indices', function (st) {
574
+ t.test('uses indices notation for arrays when arrayFormat=indices', function (st) {
390
575
  st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' }), 'a%5B0%5D=b&a%5B1%5D=c');
391
576
  st.end();
392
577
  });
393
578
 
394
- t.test('uses repeat notation for arrays when no arrayFormat=repeat', function (st) {
579
+ t.test('uses repeat notation for arrays when arrayFormat=repeat', function (st) {
395
580
  st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' }), 'a=b&a=c');
396
581
  st.end();
397
582
  });
398
583
 
399
- t.test('uses brackets notation for arrays when no arrayFormat=brackets', function (st) {
584
+ t.test('uses brackets notation for arrays when arrayFormat=brackets', function (st) {
400
585
  st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' }), 'a%5B%5D=b&a%5B%5D=c');
401
586
  st.end();
402
587
  });
@@ -493,10 +678,11 @@ test('stringify()', function (t) {
493
678
  });
494
679
 
495
680
  t.test('skips properties that are part of the object prototype', function (st) {
496
- Object.prototype.crash = 'test';
681
+ st.intercept(Object.prototype, 'crash', { value: 'test' });
682
+
497
683
  st.equal(qs.stringify({ a: 'b' }), 'a=b');
498
684
  st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
499
- delete Object.prototype.crash;
685
+
500
686
  st.end();
501
687
  });
502
688
 
@@ -520,10 +706,12 @@ test('stringify()', function (t) {
520
706
  });
521
707
 
522
708
  t.test('does not blow up when Buffer global is missing', function (st) {
523
- var tempBuffer = global.Buffer;
524
- delete global.Buffer;
709
+ var restore = mockProperty(global, 'Buffer', { 'delete': true });
710
+
525
711
  var result = qs.stringify({ a: 'b', c: 'd' });
526
- global.Buffer = tempBuffer;
712
+
713
+ restore();
714
+
527
715
  st.equal(result, 'a=b&c=d');
528
716
  st.end();
529
717
  });
@@ -572,9 +760,17 @@ test('stringify()', function (t) {
572
760
  };
573
761
 
574
762
  st.equal(
575
- qs.stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true }),
763
+ qs.stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
576
764
  'filters[$and][0][function]=gte&filters[$and][0][arguments][0][function]=hour_of_day&filters[$and][0][arguments][1]=0&filters[$and][1][function]=lte&filters[$and][1][arguments][0][function]=hour_of_day&filters[$and][1][arguments][1]=23'
577
765
  );
766
+ st.equal(
767
+ qs.stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
768
+ 'filters[$and][][function]=gte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=0&filters[$and][][function]=lte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=23'
769
+ );
770
+ st.equal(
771
+ qs.stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),
772
+ 'filters[$and][function]=gte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=0&filters[$and][function]=lte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=23'
773
+ );
578
774
 
579
775
  st.end();
580
776
  });
@@ -687,13 +883,28 @@ test('stringify()', function (t) {
687
883
  st.end();
688
884
  });
689
885
 
886
+ t.test('receives the default encoder as a second argument', function (st) {
887
+ st.plan(8);
888
+
889
+ qs.stringify({ a: 1, b: new Date(), c: true, d: [1] }, {
890
+ encoder: function (str) {
891
+ st.match(typeof str, /^(?:string|number|boolean)$/);
892
+ return '';
893
+ }
894
+ });
895
+
896
+ st.end();
897
+ });
898
+
690
899
  t.test('receives the default encoder as a second argument', function (st) {
691
900
  st.plan(2);
901
+
692
902
  qs.stringify({ a: 1 }, {
693
903
  encoder: function (str, defaultEncoder) {
694
904
  st.equal(defaultEncoder, utils.encode);
695
905
  }
696
906
  });
907
+
697
908
  st.end();
698
909
  });
699
910
 
@@ -821,16 +1032,53 @@ test('stringify()', function (t) {
821
1032
  st.equal(
822
1033
  qs.stringify(
823
1034
  { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
824
- { encodeValuesOnly: true }
1035
+ { encodeValuesOnly: true, arrayFormat: 'indices' }
1036
+ ),
1037
+ 'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h',
1038
+ 'encodeValuesOnly + indices'
1039
+ );
1040
+ st.equal(
1041
+ qs.stringify(
1042
+ { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
1043
+ { encodeValuesOnly: true, arrayFormat: 'brackets' }
1044
+ ),
1045
+ 'a=b&c[]=d&c[]=e%3Df&f[][]=g&f[][]=h',
1046
+ 'encodeValuesOnly + brackets'
1047
+ );
1048
+ st.equal(
1049
+ qs.stringify(
1050
+ { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
1051
+ { encodeValuesOnly: true, arrayFormat: 'repeat' }
1052
+ ),
1053
+ 'a=b&c=d&c=e%3Df&f=g&f=h',
1054
+ 'encodeValuesOnly + repeat'
1055
+ );
1056
+
1057
+ st.equal(
1058
+ qs.stringify(
1059
+ { a: 'b', c: ['d', 'e'], f: [['g'], ['h']] },
1060
+ { arrayFormat: 'indices' }
1061
+ ),
1062
+ 'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h',
1063
+ 'no encodeValuesOnly + indices'
1064
+ );
1065
+ st.equal(
1066
+ qs.stringify(
1067
+ { a: 'b', c: ['d', 'e'], f: [['g'], ['h']] },
1068
+ { arrayFormat: 'brackets' }
825
1069
  ),
826
- 'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h'
1070
+ 'a=b&c%5B%5D=d&c%5B%5D=e&f%5B%5D%5B%5D=g&f%5B%5D%5B%5D=h',
1071
+ 'no encodeValuesOnly + brackets'
827
1072
  );
828
1073
  st.equal(
829
1074
  qs.stringify(
830
- { a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }
1075
+ { a: 'b', c: ['d', 'e'], f: [['g'], ['h']] },
1076
+ { arrayFormat: 'repeat' }
831
1077
  ),
832
- 'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h'
1078
+ 'a=b&c=d&c=e&f=g&f=h',
1079
+ 'no encodeValuesOnly + repeat'
833
1080
  );
1081
+
834
1082
  st.end();
835
1083
  });
836
1084
 
@@ -867,13 +1115,19 @@ test('stringify()', function (t) {
867
1115
  st.end();
868
1116
  });
869
1117
 
870
- t.test('adds the right sentinel when instructed to and the charset is utf-8', function (st) {
871
- st.equal(qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' }), 'utf8=%E2%9C%93&a=%C3%A6');
872
- st.end();
873
- });
1118
+ t.test('`charsetSentinel` option', function (st) {
1119
+ st.equal(
1120
+ qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' }),
1121
+ 'utf8=%E2%9C%93&a=%C3%A6',
1122
+ 'adds the right sentinel when instructed to and the charset is utf-8'
1123
+ );
1124
+
1125
+ st.equal(
1126
+ qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' }),
1127
+ 'utf8=%26%2310003%3B&a=%E6',
1128
+ 'adds the right sentinel when instructed to and the charset is iso-8859-1'
1129
+ );
874
1130
 
875
- t.test('adds the right sentinel when instructed to and the charset is iso-8859-1', function (st) {
876
- st.equal(qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' }), 'utf8=%26%2310003%3B&a=%E6');
877
1131
  st.end();
878
1132
  });
879
1133
 
@@ -924,13 +1178,15 @@ test('stringify()', function (t) {
924
1178
  var withArray = { a: { b: [{ c: 'd', e: 'f' }] } };
925
1179
 
926
1180
  st.equal(qs.stringify(obj, { encode: false }), 'a[b][c]=d&a[b][e]=f', 'no array, no arrayFormat');
927
- st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'bracket' }), 'a[b][c]=d&a[b][e]=f', 'no array, bracket');
1181
+ st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'brackets' }), 'a[b][c]=d&a[b][e]=f', 'no array, bracket');
928
1182
  st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'indices' }), 'a[b][c]=d&a[b][e]=f', 'no array, indices');
1183
+ st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'repeat' }), 'a[b][c]=d&a[b][e]=f', 'no array, repeat');
929
1184
  st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'comma' }), 'a[b][c]=d&a[b][e]=f', 'no array, comma');
930
1185
 
931
1186
  st.equal(qs.stringify(withArray, { encode: false }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, no arrayFormat');
932
- st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'bracket' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, bracket');
1187
+ st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'brackets' }), 'a[b][][c]=d&a[b][][e]=f', 'array, bracket');
933
1188
  st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'indices' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, indices');
1189
+ st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'repeat' }), 'a[b][c]=d&a[b][e]=f', 'array, repeat');
934
1190
  st.equal(
935
1191
  qs.stringify(withArray, { encode: false, arrayFormat: 'comma' }),
936
1192
  '???',
@@ -943,10 +1199,21 @@ test('stringify()', function (t) {
943
1199
 
944
1200
  t.test('stringifies sparse arrays', function (st) {
945
1201
  /* eslint no-sparse-arrays: 0 */
946
- st.equal(qs.stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true }), 'a[1]=2&a[4]=1');
947
- st.equal(qs.stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true }), 'a[1][b][2][c]=1');
948
- st.equal(qs.stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true }), 'a[1][2][3][c]=1');
949
- st.equal(qs.stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true }), 'a[1][2][3][c][1]=1');
1202
+ st.equal(qs.stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[1]=2&a[4]=1');
1203
+ st.equal(qs.stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=2&a[]=1');
1204
+ st.equal(qs.stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a=2&a=1');
1205
+
1206
+ st.equal(qs.stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[1][b][2][c]=1');
1207
+ st.equal(qs.stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[][b][][c]=1');
1208
+ st.equal(qs.stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a[b][c]=1');
1209
+
1210
+ st.equal(qs.stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[1][2][3][c]=1');
1211
+ st.equal(qs.stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[][][][c]=1');
1212
+ st.equal(qs.stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a[c]=1');
1213
+
1214
+ st.equal(qs.stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[1][2][3][c][1]=1');
1215
+ st.equal(qs.stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[][][][c][]=1');
1216
+ st.equal(qs.stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a[c]=1');
950
1217
 
951
1218
  st.end();
952
1219
  });
@@ -957,7 +1224,21 @@ test('stringify()', function (t) {
957
1224
  test('stringifies empty keys', function (t) {
958
1225
  emptyTestCases.forEach(function (testCase) {
959
1226
  t.test('stringifies an object with empty string key with ' + testCase.input, function (st) {
960
- st.deepEqual(qs.stringify(testCase.withEmptyKeys, { encode: false }), testCase.stringifyOutput);
1227
+ st.deepEqual(
1228
+ qs.stringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'indices' }),
1229
+ testCase.stringifyOutput.indices,
1230
+ 'test case: ' + testCase.input + ', indices'
1231
+ );
1232
+ st.deepEqual(
1233
+ qs.stringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'brackets' }),
1234
+ testCase.stringifyOutput.brackets,
1235
+ 'test case: ' + testCase.input + ', brackets'
1236
+ );
1237
+ st.deepEqual(
1238
+ qs.stringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'repeat' }),
1239
+ testCase.stringifyOutput.repeat,
1240
+ 'test case: ' + testCase.input + ', repeat'
1241
+ );
961
1242
 
962
1243
  st.end();
963
1244
  });
@@ -966,6 +1247,8 @@ test('stringifies empty keys', function (t) {
966
1247
  t.test('edge case with object/arrays', function (st) {
967
1248
  st.deepEqual(qs.stringify({ '': { '': [2, 3] } }, { encode: false }), '[][0]=2&[][1]=3');
968
1249
  st.deepEqual(qs.stringify({ '': { '': [2, 3], a: 2 } }, { encode: false }), '[][0]=2&[][1]=3&[a]=2');
1250
+ st.deepEqual(qs.stringify({ '': { '': [2, 3] } }, { encode: false, arrayFormat: 'indices' }), '[][0]=2&[][1]=3');
1251
+ st.deepEqual(qs.stringify({ '': { '': [2, 3], a: 2 } }, { encode: false, arrayFormat: 'indices' }), '[][0]=2&[][1]=3&[a]=2');
969
1252
 
970
1253
  st.end();
971
1254
  });
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  "jsii-docgen": "^3.8.31",
54
54
  "jsii-pacmak": "^1.95.0",
55
55
  "jsii-rosetta": "5.3.x",
56
- "projen": "0.80.7",
56
+ "projen": "0.80.8",
57
57
  "standard-version": "^9",
58
58
  "ts-jest": "^27",
59
59
  "typescript": "^5"
@@ -84,7 +84,7 @@
84
84
  },
85
85
  "main": "lib/index.js",
86
86
  "license": "Apache-2.0",
87
- "version": "2.0.775",
87
+ "version": "2.0.776",
88
88
  "jest": {
89
89
  "testMatch": [
90
90
  "<rootDir>/src/**/__tests__/**/*.ts?(x)",