Skip to content

Commit f0361df

Browse files
committed
fix(routeToRegExp): match wildcard without trailing slashes as well
1 parent e848ec7 commit f0361df

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ describe("routeToRegExp", () => {
2929
match: [["/path/anything/foo"], ["/path//foo"], ["/path//foo/"]],
3030
},
3131
"/path/**": {
32-
regex: /^\/path\/.*\/?$/,
33-
match: [
34-
["/path/"],
35-
// ["/path"], // TODO
36-
["/path/anything/more"],
37-
],
32+
regex: /^\/path\/?.*\/?$/,
33+
match: [["/path/"], ["/path"], ["/path/anything/more"]],
3834
},
3935
} as const;
4036

0 commit comments

Comments
 (0)