Skip to content

Commit 99caad7

Browse files
Refactor parseQueryString function for improved handling of empty pairs and key-value parsing
1 parent 577ae89 commit 99caad7

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Sprint-2/implement/querystring.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,30 @@ function parseQueryString(queryString) {
33
if (queryString.length === 0) {
44
return queryParams;
55
}
6+
67
const keyValuePairs = queryString.split("&");
78

89
for (const pair of keyValuePairs) {
9-
const [key, value] = pair.split("=");
10-
queryParams[key] = value;
10+
if(pair===""){
11+
continue
12+
}
13+
const equalIndex=pair.indexOf("=")
14+
if (equalIndex === -1) {
15+
queryParams[pair]="";
16+
continue
17+
}
18+
const key=pair.substring(0,equalIndex)
19+
const value=pair.substring(equalIndex+1)
20+
queryParams[key]=value
21+
1122
}
1223

1324
return queryParams;
1425
}
26+
//console.log(parseQueryString("equationxy+1"));
1527

1628
module.exports = parseQueryString;
29+
30+
31+
32+

0 commit comments

Comments
 (0)