Skip to content

Commit 27c9c9d

Browse files
committed
fix: decode keys and values in parseQueryString and add test case
1 parent 21c0ee2 commit 27c9c9d

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Sprint-2/implement/querystring.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ function parseQueryString(queryString) {
77

88
for (const pair of keyValuePairs) {
99
const [key, ...valueParts] = pair.split("=");
10-
queryParams[key] = valueParts.join("=");
10+
const decodedKey = decodeURIComponent(key);
11+
const decodedValue = decodeURIComponent(valueParts.join("="));
12+
queryParams[decodedKey] = decodedValue;
1113
}
1214

1315
return queryParams;

Sprint-2/implement/querystring.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ test("handles key without value", () => {
2222
key3: "value3",
2323
});
2424
});
25+
26+
test("should decode URL-encoded query strings", () => {
27+
const queryString = "tags%5B%5D=hello%20world";
28+
const expected = { "tags[]": "hello world" };
29+
const result = parseQueryString(queryString);
30+
expect(result).toEqual(expected);
31+
});

0 commit comments

Comments
 (0)