Skip to content

Commit 40dd637

Browse files
authored
fix(router): handle trailing-slash routes in path segment boundary check (#6413)
1 parent bef56e2 commit 40dd637

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

platform/src/components/aws/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ async function handler(event) {
15371537
|| (host.includes("*") && new RegExp(host).test(requestHostRegexPattern));
15381538
if (!hostMatches) return;
15391539
1540-
const pathMatches = event.request.uri.startsWith(path) && (event.request.uri === path || event.request.uri[path.length] === '/' || path === '/');
1540+
const pathMatches = event.request.uri.startsWith(path) && (event.request.uri === path || path.endsWith('/') || event.request.uri[path.length] === '/' || path === '/');
15411541
if (!pathMatches) return;
15421542
15431543
match = {

platform/test/components/router-path-matching.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe("Router path matching", () => {
1616
return (
1717
requestUri.startsWith(routePath) &&
1818
(requestUri === routePath ||
19+
routePath.endsWith("/") ||
1920
requestUri[routePath.length] === "/" ||
2021
routePath === "/")
2122
);
@@ -123,6 +124,17 @@ describe("Router path matching", () => {
123124
});
124125
});
125126

127+
describe("trailing-slash routes", () => {
128+
it("should match subpaths under trailing-slash route", () => {
129+
expect(pathMatches("/public/2025-11/image.jpg", "/public/")).toBe(true);
130+
expect(pathMatches("/public/", "/public/")).toBe(true);
131+
});
132+
133+
it("should NOT match non-segment continuations", () => {
134+
expect(pathMatches("/publicfile", "/public/")).toBe(false);
135+
});
136+
});
137+
126138
describe("priority testing (longest match)", () => {
127139
it("should support longest path matching", () => {
128140
// When multiple routes could match, the Router picks the longest

0 commit comments

Comments
 (0)