diff --git a/packages/qwik-city/runtime/src/route-matcher.ts b/packages/qwik-city/runtime/src/route-matcher.ts index 1fb4018dc30..5ac028fbf66 100644 --- a/packages/qwik-city/runtime/src/route-matcher.ts +++ b/packages/qwik-city/runtime/src/route-matcher.ts @@ -144,8 +144,7 @@ function recursiveScan( } let pathIdx = pathLength; const sep = suffix + '/'; - let depthWatchdog = 5; - while (pathIdx >= pathStart && depthWatchdog--) { + while (pathIdx >= pathStart) { const match = matchRoutePart(route, routeStart, routeLength, path, pathIdx, pathLength); if (match) { let value = path.substring(pathStart, Math.min(pathIdx, pathLength)); @@ -155,7 +154,11 @@ function recursiveScan( match[paramName] = decodeURIComponent(value); return match; } - pathIdx = lastIndexOf(path, pathStart, sep, pathIdx, pathStart - 1) + sep.length; + const newPathIdx = lastIndexOf(path, pathStart, sep, pathIdx, pathStart - 1) + sep.length; + if (pathIdx === newPathIdx) { + break; + } + pathIdx = newPathIdx; } return null; } diff --git a/packages/qwik-city/runtime/src/route-matcher.unit.ts b/packages/qwik-city/runtime/src/route-matcher.unit.ts index 21424f49fac..69f499016e6 100644 --- a/packages/qwik-city/runtime/src/route-matcher.unit.ts +++ b/packages/qwik-city/runtime/src/route-matcher.unit.ts @@ -66,6 +66,12 @@ describe('route-matcher', () => { assert.deepEqual(matchRoute('/seg/[...rest]', '/seg/a/b/c'), { rest: 'a/b/c' }); }); + test('should match /seg/[...rest]/a/b/c/d/e', () => { + assert.deepEqual(matchRoute('/seg/[...rest]/a/b/c/d/e', '/seg/a/b/c/d/e'), { + rest: '', + }); + }); + test('should match /seg/[...rest] with trailing slash', () => { assert.deepEqual(matchRoute('/seg/[...rest]/', '/seg/a/b/c'), { rest: 'a/b/c' }); });