Skip to content

Commit 4d024df

Browse files
authored
fix(parseQuery): use object with null prototype (#286)
1 parent e383832 commit 4d024df

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/query.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export type QueryObject = Record<string, QueryValue | QueryValue[]>;
1818

1919
export type ParsedQuery = Record<string, string | string[]>;
2020

21+
const EmptyObject = /* @__PURE__ */ (() => {
22+
const C = function () {};
23+
C.prototype = Object.create(null);
24+
return C;
25+
})() as unknown as { new (): any };
26+
2127
/**
2228
* Parses and decodes a query string into an object.
2329
*
@@ -31,7 +37,7 @@ export type ParsedQuery = Record<string, string | string[]>;
3137
export function parseQuery<T extends ParsedQuery = ParsedQuery>(
3238
parametersString = "",
3339
): T {
34-
const object: ParsedQuery = {};
40+
const object: ParsedQuery = new EmptyObject();
3541
if (parametersString[0] === "?") {
3642
parametersString = parametersString.slice(1);
3743
}

test/query.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ describe("getQuery", () => {
8686
"http://foo.com/?param=%7B%22a%22:%5B%7B%22obj%22:%5B1,2,3%5D%7D%5D%7D": {
8787
param: '{"a":[{"obj":[1,2,3]}]}',
8888
},
89+
"http://foo.com/?toString=foo": { toString: "foo" },
8990
};
9091

9192
for (const t in tests) {

0 commit comments

Comments
 (0)