@@ -162,6 +162,23 @@ test('query strings having pipe separated arrays and format option as `separator
162162 } ) , { foo : [ 'bar' , 'baz' ] } ) ;
163163} ) ;
164164
165+ test ( 'single value with encoded separator should not be split into array' , t => {
166+ // Test for issue #336 - encoded separators should not cause array splitting
167+ const value = encodeURIComponent ( 'a|b' ) ; // 'a%7Cb'
168+ t . deepEqual ( queryString . parse ( `foo=${ value } ` , {
169+ arrayFormat : 'separator' ,
170+ arrayFormatSeparator : '|' ,
171+ } ) , { foo : 'a|b' } ) ;
172+
173+ // Multiple values with encoded separators in them
174+ const value1 = encodeURIComponent ( 'a|b' ) ;
175+ const value2 = encodeURIComponent ( 'c|d' ) ;
176+ t . deepEqual ( queryString . parse ( `foo=${ value1 } |${ value2 } ` , {
177+ arrayFormat : 'separator' ,
178+ arrayFormatSeparator : '|' ,
179+ } ) , { foo : [ 'a|b' , 'c|d' ] } ) ;
180+ } ) ;
181+
165182test ( 'query strings having brackets arrays with null and format option as `bracket`' , t => {
166183 t . deepEqual ( queryString . parse ( 'bar[]&foo[]=a&foo[]&foo[]=' , {
167184 arrayFormat : 'bracket' ,
@@ -407,7 +424,7 @@ test('value should not be decoded twice with `arrayFormat` option set as `separa
407424test ( 'value separated by encoded comma will not be parsed as array with `arrayFormat` option set to `comma`' , t => {
408425 const value = '1,2,3' ;
409426 t . deepEqual ( queryString . parse ( `id=${ encodeURIComponent ( value ) } ` , { arrayFormat : 'comma' , parseNumbers : true } ) , {
410- id : [ 1 , 2 , 3 ] ,
427+ id : '1,2,3' ,
411428 } ) ;
412429} ) ;
413430
0 commit comments