Skip to content

Commit 6b31d1d

Browse files
committed
fix: split on first = only to correctly parse values containing =
1 parent 5bd4e7e commit 6b31d1d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Sprint-2/implement/querystring.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ function parseQueryString(queryString) {
1010
const cleaned = queryString.startsWith("?")
1111
? queryString.slice(1)
1212
: queryString;
13-
const keyValuePairs = cleaned.split("&").filter(Boolean);
14-
15-
for (const pair of keyValuePairs) {
16-
// Only split on the first =
17-
const equalIndex = pair.indexOf("=");
18-
19-
if (equalIndex === -1) {
20-
// key without = → value is empty string
21-
queryParams[pair] = "";
22-
} else {
23-
const key = pair.slice(0, equalIndex);
24-
const value = pair.slice(equalIndex + 1);
13+
14+
// Split into segments and ignore empty ones
15+
const segments = cleaned.split("&").filter(Boolean);
16+
17+
for (const segment of segments) {
18+
// Split only on the first =, but everything after is a value
19+
const eqIndex = segment.indexOf("=");
20+
21+
const key = eqIndex === -1 ? segment : segment.slice(0, eqIndex);
22+
const value = eqIndex === -1 ? "" : segment.slice(eqIndex + 1);
23+
24+
if (key) {
2525
queryParams[key] = value;
2626
}
2727
}

0 commit comments

Comments
 (0)