@@ -110,7 +110,8 @@ test('handle multiple values and preserve appearance order with indexes', t => {
110
110
} ) ;
111
111
112
112
test ( 'query strings params including embedded `=`' , t => {
113
- t . deepEqual ( queryString . parse ( '?param=https%3A%2F%2Fsomeurl%3Fid%3D2837' ) , { param : 'https://someurl?id=2837' } ) ;
113
+ const value = 'https://someurl?id=2837' ;
114
+ t . deepEqual ( queryString . parse ( `param=${ encodeURIComponent ( value ) } ` ) , { param : 'https://someurl?id=2837' } ) ;
114
115
} ) ;
115
116
116
117
test ( 'object properties' , t => {
@@ -215,6 +216,16 @@ test('query strings having a brackets+separator array and format option as `brac
215
216
} ) , { foo : [ '' ] } ) ;
216
217
} ) ;
217
218
219
+ test ( 'query strings having a brackets+separator array and format option as `bracket-separator` with a URL encoded value' , t => {
220
+ const key = 'foo[]' ;
221
+ const value = 'a,b,c,d,e,f' ;
222
+ t . deepEqual ( queryString . parse ( `?${ encodeURIComponent ( key ) } =${ encodeURIComponent ( value ) } ` , {
223
+ arrayFormat : 'bracket-separator' ,
224
+ } ) , {
225
+ foo : [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' ] ,
226
+ } ) ;
227
+ } ) ;
228
+
218
229
test ( 'query strings having = within parameters (i.e. GraphQL IDs)' , t => {
219
230
t . deepEqual ( queryString . parse ( 'foo=bar=&foo=ba=z=' ) , { foo : [ 'bar=' , 'ba=z=' ] } ) ;
220
231
} ) ;
@@ -305,7 +316,8 @@ test('decode keys and values', t => {
305
316
} ) ;
306
317
307
318
test ( 'disable decoding of keys and values' , t => {
308
- t . deepEqual ( queryString . parse ( 'tags=postal%20office,burger%2C%20fries%20and%20coke' , { decode : false } ) , { tags : 'postal%20office,burger%2C%20fries%20and%20coke' } ) ;
319
+ const value = 'postal office,burger, fries and coke' ;
320
+ t . deepEqual ( queryString . parse ( `tags=${ encodeURIComponent ( value ) } ` , { decode : false } ) , { tags : 'postal%20office%2Cburger%2C%20fries%20and%20coke' } ) ;
309
321
} ) ;
310
322
311
323
test ( 'number value returns as string by default' , t => {
@@ -376,7 +388,8 @@ test('parse throws TypeError for invalid arrayFormatSeparator', t => {
376
388
} ) ;
377
389
378
390
test ( 'query strings having comma encoded and format option as `comma`' , t => {
379
- t . deepEqual ( queryString . parse ( 'foo=zero%2Cone,two%2Cthree' , { arrayFormat : 'comma' } ) , {
391
+ const values = [ 'zero,one' , 'two,three' ] ;
392
+ t . deepEqual ( queryString . parse ( `foo=${ encodeURIComponent ( values [ 0 ] ) } ,${ encodeURIComponent ( values [ 1 ] ) } ` , { arrayFormat : 'comma' } ) , {
380
393
foo : [
381
394
'zero,one' ,
382
395
'two,three' ,
@@ -392,7 +405,8 @@ test('value should not be decoded twice with `arrayFormat` option set as `separa
392
405
393
406
// See https://github.com/sindresorhus/query-string/issues/242
394
407
test ( 'value separated by encoded comma will not be parsed as array with `arrayFormat` option set to `comma`' , t => {
395
- t . deepEqual ( queryString . parse ( 'id=1%2C2%2C3' , { arrayFormat : 'comma' , parseNumbers : true } ) , {
408
+ const value = '1,2,3' ;
409
+ t . deepEqual ( queryString . parse ( `id=${ encodeURIComponent ( value ) } ` , { arrayFormat : 'comma' , parseNumbers : true } ) , {
396
410
id : [ 1 , 2 , 3 ] ,
397
411
} ) ;
398
412
} ) ;
@@ -406,7 +420,8 @@ test('query strings having (:list) colon-list-separator arrays including null va
406
420
} ) ;
407
421
408
422
test ( 'types option: can override a parsed number to be a string ' , t => {
409
- t . deepEqual ( queryString . parse ( 'phoneNumber=%2B380951234567' , {
423
+ const phoneNumber = '+380951234567' ;
424
+ t . deepEqual ( queryString . parse ( `phoneNumber=${ encodeURIComponent ( phoneNumber ) } ` , {
410
425
parseNumbers : true ,
411
426
types : {
412
427
phoneNumber : 'string' ,
@@ -426,7 +441,7 @@ test('types option: can override a parsed boolean value to be a string', t => {
426
441
} ) ;
427
442
428
443
test ( 'types option: can override parsed numbers arrays to be string[]' , t => {
429
- t . deepEqual ( queryString . parse ( 'ids=999%2C998%2C997 &items=1%2C2%2C3 ' , {
444
+ t . deepEqual ( queryString . parse ( 'ids=999,998,997 &items=1,2,3 ' , {
430
445
arrayFormat : 'comma' ,
431
446
parseNumbers : true ,
432
447
types : {
@@ -439,7 +454,7 @@ test('types option: can override parsed numbers arrays to be string[]', t => {
439
454
} ) ;
440
455
441
456
test ( 'types option: can override string arrays to be number[]' , t => {
442
- t . deepEqual ( queryString . parse ( 'ids=001%2C002%2C003 &items=1%2C2%2C3 ' , {
457
+ t . deepEqual ( queryString . parse ( 'ids=1,2,3 &items=1,2,3 ' , {
443
458
arrayFormat : 'comma' ,
444
459
types : {
445
460
ids : 'number[]' ,
@@ -451,7 +466,7 @@ test('types option: can override string arrays to be number[]', t => {
451
466
} ) ;
452
467
453
468
test ( 'types option: can override an array to be string' , t => {
454
- t . deepEqual ( queryString . parse ( 'ids=001%2C002%2C003 &items=1%2C2%2C3 ' , {
469
+ t . deepEqual ( queryString . parse ( 'ids=001,002,003 &items=1,2,3 ' , {
455
470
arrayFormat : 'comma' ,
456
471
parseNumbers : true ,
457
472
types : {
@@ -488,7 +503,7 @@ test('types option: when value is not of specified type, it will safely parse th
488
503
} ) ;
489
504
490
505
test ( 'types option: array types will have no effect if arrayFormat is set to "none"' , t => {
491
- t . deepEqual ( queryString . parse ( 'ids=001%2C002%2C003 &foods=apple%2Corange%2Cmango ' , {
506
+ t . deepEqual ( queryString . parse ( 'ids=001,002,003 &foods=apple,orange,mango ' , {
492
507
arrayFormat : 'none' ,
493
508
types : {
494
509
ids : 'number[]' ,
@@ -512,7 +527,7 @@ test('types option: will parse the value as number if specified in type but pars
512
527
} ) ;
513
528
514
529
test ( 'types option: all supported types work in conjunction with one another' , t => {
515
- t . deepEqual ( queryString . parse ( 'ids=001%2C002%2C003 &items=1%2C2%2C3 &price=22%2E00 &numbers=1%2C2%2C3 &double=5&number=20' , {
530
+ t . deepEqual ( queryString . parse ( 'ids=001,002,003 &items=1,2,3 &price=22.00 &numbers=1,2,3 &double=5&number=20' , {
516
531
arrayFormat : 'comma' ,
517
532
types : {
518
533
ids : 'string' ,
0 commit comments