Skip to content

Commit 205430d

Browse files
committed
fix(routeToRegExp): keep wildcard as _
1 parent 0f72045 commit 205430d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/regexp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function routeToRegExp(route: string = "/"): RegExp {
55
if (segment === "*") {
66
reSegments.push("[^/]*");
77
} else if (segment === "**") {
8-
reSegments.push("?.*");
8+
reSegments.push("?(?<_>.*)");
99
} else if (segment.includes(":")) {
1010
reSegments.push(
1111
segment

test/regexp.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ describe("routeToRegExp", () => {
2929
match: [["/path/anything/foo"], ["/path//foo"], ["/path//foo/"]],
3030
},
3131
"/path/**": {
32-
regex: /^\/path\/?.*\/?$/,
33-
match: [["/path/"], ["/path"], ["/path/anything/more"]],
32+
regex: /^\/path\/?(?<_>.*)\/?$/,
33+
match: [
34+
["/path/"],
35+
["/path"],
36+
["/path/anything/more", { _: "anything/more" }],
37+
],
3438
},
3539
} as const;
3640

0 commit comments

Comments
 (0)