Skip to content

Commit

Permalink
Use Map instead of Object for parsing query strings (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakota628 authored Jun 21, 2021
1 parent 0745436 commit a22abf8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/middlewares/parsers/req.parameter.mutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ export class RequestParameterMutator {

private validateReservedCharacters(
name: string,
pairs: { [key: string]: string[] },
pairs: Map<string, string[]>,
) {
const vs = pairs[name];
const vs = pairs.get(name);
if (!vs) return;
for (const v of vs) {
if (v?.match(RESERVED_CHARS)) {
Expand All @@ -345,14 +345,14 @@ export class RequestParameterMutator {
}
}

private parseQueryStringUndecoded(qs: string) {
if (!qs) return {};
private parseQueryStringUndecoded(qs: string): Map<string, string[]> {
if (!qs) return new Map<string, string[]>();
const q = qs.replace('?', '');
return q.split('&').reduce((m, p) => {
const [k, v] = p.split('=');
m[k] = m[k] ?? [];
m[k].push(v);
m.set(k, m.get(k) ?? []);
m.get(k)!.push(v);
return m;
}, {});
}, new Map<string, string[]>());
}
}

0 comments on commit a22abf8

Please sign in to comment.