File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff 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 = {
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments