The var declarations inside the loop are hoisted to function scope, so separator, rawKey, and rawValue leak out of each iteration.
Exorcism strategy: Declare the per-iteration values with const inside a for...of loop.
Implicit coercionHEX
Séance Chamber
Approval: Approved on 2026-11-07
Requirements
Requirements: Query string parser
Acceptance Criteria
THE parseQueryString function SHALL accept a query string with or without a leading question mark and SHALL return an object that maps decoded keys to decoded values.
WHEN the input is empty or contains only a question mark, THE parseQueryString function SHALL return an empty object.
WHEN a pair has no equals sign, THE parseQueryString function SHALL use the empty string as its value.
WHEN a key appears more than once, THE parseQueryString function SHALL return an array that holds every value in order of appearance.
WHEN a key or a value contains a plus sign, THE parseQueryString function SHALL decode it as a space before percent-decoding.
IF a percent-encoded sequence is malformed, THENTHE parseQueryString function SHALL throw a URIError.
WHERE a key is __proto__, THE parseQueryString function SHALL ignore the pair.
Design
Design: Query string parser
Entry function: parseQueryString(query).
Input: a string, the URL query part with or without a leading question mark.
Output: an object that maps each decoded key to a decoded string, or to an array of strings when the key repeats.
The function is pure and deterministic. The TypeScript version types the result as a record of strings or string arrays, uses startsWith and Array.isArray instead of loose comparisons, and skips the key explicitly.
Laboratory
Verified
Verified behavioral equivalence across 1,000 generated inputs.
This is empirical evidence from randomly generated inputs. Other inputs were not checked.
Completed in 375 ms.
Target stack: TypeScript 6 (strict mode, ES2022). Created .
1export type QueryValue = string | string[];
2export type QueryResult = Record<string, QueryValue>;