File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change 11function parseQueryString ( queryString ) {
22 const queryParams = { } ;
3- if ( queryString . length === 0 ) {
3+
4+ // Handle empty string or just "?"
5+ if ( ! queryString || queryString === "?" ) {
46 return queryParams ;
57 }
6- const keyValuePairs = queryString . split ( "&" ) ;
8+
9+ // Remove leading ? if present
10+ const cleaned = queryString . startsWith ( "?" )
11+ ? queryString . slice ( 1 )
12+ : queryString ;
13+ const keyValuePairs = cleaned . split ( "&" ) . filter ( Boolean ) ;
714
815 for ( const pair of keyValuePairs ) {
9- const [ key , value ] = pair . split ( "=" ) ;
10- queryParams [ key ] = value ;
16+ // Only split on the first =
17+ const equalIndex = pair . indexOf ( "=" ) ;
18+
19+ if ( equalIndex === - 1 ) {
20+ // key without = → value is empty string
21+ queryParams [ pair ] = "" ;
22+ } else {
23+ const key = pair . slice ( 0 , equalIndex ) ;
24+ const value = pair . slice ( equalIndex + 1 ) ;
25+ queryParams [ key ] = value ;
26+ }
1127 }
1228
1329 return queryParams ;
You can’t perform that action at this time.
0 commit comments