File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
open-next/src/core/routing
tests-unit/tests/core/routing Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -41,10 +41,18 @@ export function convertFromQueryString(query: string) {
41
41
return queryParts . reduce (
42
42
( acc , part ) => {
43
43
const [ key , value ] = part . split ( "=" ) ;
44
- acc [ key ] = value ;
44
+ if ( key in acc ) {
45
+ if ( Array . isArray ( acc [ key ] ) ) {
46
+ acc [ key ] . push ( value ) ;
47
+ } else {
48
+ acc [ key ] = [ acc [ key ] , value ] ;
49
+ }
50
+ } else {
51
+ acc [ key ] = value ;
52
+ }
45
53
return acc ;
46
54
} ,
47
- { } as Record < string , string > ,
55
+ { } as Record < string , string | string [ ] > ,
48
56
) ;
49
57
}
50
58
Original file line number Diff line number Diff line change @@ -107,9 +107,9 @@ describe("convertFromQueryString", () => {
107
107
} ) ;
108
108
} ) ;
109
109
110
- it ( "converts query string with multiple keys (last one wins) " , ( ) => {
110
+ it ( "converts query string with multiple keys" , ( ) => {
111
111
expect ( convertFromQueryString ( "search=value&search=other" ) ) . toEqual ( {
112
- search : " other",
112
+ search : [ "value" , " other"] ,
113
113
} ) ;
114
114
} ) ;
115
115
} ) ;
You can’t perform that action at this time.
0 commit comments