@@ -3,14 +3,40 @@ function parseQueryString(queryString) {
33 if ( queryString . length === 0 ) {
44 return queryParams ;
55 }
6+
7+ // Adds percentage-encoded characters
8+ queryString = changePEC ( queryString )
9+
10+ // Replaces + with space
11+ queryString = queryString . replaceAll ( "+" , " " )
12+
613 const keyValuePairs = queryString . split ( "&" ) ;
714
815 for ( const pair of keyValuePairs ) {
9- const [ key , value ] = pair . split ( "=" ) ;
16+ if ( pair !== "" ) {
17+ let index = pair . indexOf ( "=" )
18+ if ( ! pair . includes ( "=" ) ) { index = pair . length }
19+ const [ key , value ] = [ pair . slice ( 0 , index ) , pair . slice ( index + 1 ) ]
1020 queryParams [ key ] = value ;
21+ }
22+ else { } ;
1123 }
1224
1325 return queryParams ;
1426}
1527
28+ // this function below can have the object PEC expanded to include all percentage-encoded characters
29+ // currently without adding this database, an unknown PEC could cause the code to get stuck in an infinite loop
30+
31+ function changePEC ( string ) {
32+ const PEC = { "%24" : "$" , "%2F" : "/" }
33+ while ( string . includes ( "%" ) ) {
34+ const index = string . indexOf ( "%" ) ;
35+ const code = string . slice ( index , index + 3 ) ;
36+ if ( PEC [ code ] ) { string = string . replace ( code , PEC [ code ] ) ; }
37+ else { break ; }
38+ }
39+ return string
40+ }
41+
1642module . exports = parseQueryString ;
0 commit comments