Skip to content

Commit 5feb581

Browse files
committed
added decoding to the querystring.js
1 parent c24041e commit 5feb581

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Sprint-2/implement/querystring.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

Sprint-2/implement/querystring.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
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

88
test("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+
});

0 commit comments

Comments
 (0)