Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: ignore queryparams in matching #61

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ function _matchRoutes(path: string, table: RouteTable): RadixNodeData[] {
// Order should be from less specific to most specific
const matches = [];

// Ignore query parameters
path = path.split("?")[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use index check (like https://github.com/unjs/h3/blob/main/src/router.ts#L86) to handle URL like /login?returnTo=/path?foo=bar (context: unjs/h3#190)


// Wildcard
for (const [key, value] of _sortRoutesMap(table.wildcard)) {
if (path.startsWith(key)) {
Expand Down
6 changes: 6 additions & 0 deletions tests/matcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ describe("Route matcher", function () {
"/foo",
]
`);
expect(_match("/foo?key=123")).to.toMatchInlineSnapshot(`
[
"/foo/**",
"/foo",
]
`);
expect(_match("/foo/bar")).to.toMatchInlineSnapshot(`
[
"/foo/**",
Expand Down