Skip to content

Commit

Permalink
Fixes query when there is a duplicated key, now it will properly retu…
Browse files Browse the repository at this point in the history
…rn a string[], instead of last string
  • Loading branch information
AlbertSabate committed Dec 20, 2024
1 parent c86406c commit 06ceffb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/brisa/src/utils/file-system-router/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ describe('utils', () => {
// With query:
'/?test=1',
'/user/john?test=1',
'/user/john?test=1&test=2',
'/foo/bar?test=1',
'/rest/a/b/c?test=1',
'/rest2/a/b/c?test=1',
Expand Down
6 changes: 6 additions & 0 deletions packages/brisa/src/utils/file-system-router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ function getParamsAndQuery(route: string, pathname: string, url: URL) {
);

const query = { ...params, ...Object.fromEntries(url.searchParams) };
for (const key of url.searchParams.keys()) {
query[key] = url.searchParams.getAll(key);
if (query[key].length === 1) {
query[key] = query[key][0];
}
}

return { params, query };
}
Expand Down

0 comments on commit 06ceffb

Please sign in to comment.