Skip to content

Commit a9e5ff3

Browse files
committed
fix convertFromQueryString
1 parent 2fd9883 commit a9e5ff3

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/open-next/src/core/routing/util.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ export function convertFromQueryString(query: string) {
4141
return queryParts.reduce(
4242
(acc, part) => {
4343
const [key, value] = part.split("=");
44-
acc[key] = value;
44+
if (key in acc) {
45+
if (Array.isArray(acc[key])) {
46+
acc[key].push(value);
47+
} else {
48+
acc[key] = [acc[key], value];
49+
}
50+
} else {
51+
acc[key] = value;
52+
}
4553
return acc;
4654
},
47-
{} as Record<string, string>,
55+
{} as Record<string, string | string[]>,
4856
);
4957
}
5058

packages/tests-unit/tests/core/routing/util.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ describe("convertFromQueryString", () => {
107107
});
108108
});
109109

110-
it("converts query string with multiple keys (last one wins)", () => {
110+
it("converts query string with multiple keys", () => {
111111
expect(convertFromQueryString("search=value&search=other")).toEqual({
112-
search: "other",
112+
search: ["value", "other"],
113113
});
114114
});
115115
});

0 commit comments

Comments
 (0)