File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ function parseQueryString(queryString) {
66 const keyValuePairs = queryString . split ( "&" ) ;
77
88 for ( const pair of keyValuePairs ) {
9- const [ key , value ] = pair . split ( / = ( .* ) / s) ;
9+ const decodedPair = decodeURIComponent ( pair ) ;
10+ const [ key , value ] = decodedPair . split ( / = ( .* ) / s) ;
11+
1012 queryParams [ key ] = value ;
1113 }
1214
Original file line number Diff line number Diff line change 33// Below is one test case for an edge case the implementation doesn't handle well.
44// Fix the implementation for this test, and try to think of as many other edge cases as possible - write tests and fix those too.
55
6- const parseQueryString = require ( "./querystring.js" )
6+ const parseQueryString = require ( "./querystring.js" ) ;
77
88test ( "parses querystring values containing =" , ( ) => {
99 expect ( parseQueryString ( "equation=x=y+1" ) ) . toEqual ( {
1010 "equation" : "x=y+1" ,
1111 } ) ;
1212} ) ;
13+
14+ test ( "parses querystring encoded values containing =" , ( ) => {
15+ expect ( parseQueryString ( "a%25b=c%26d" ) ) . toEqual ( {
16+ "a%b" : "c&d" ,
17+ } ) ;
18+ } ) ;
You can’t perform that action at this time.
0 commit comments