Skip to content

Commit

Permalink
Removed artificial recursive limiter from recursive path matching. St…
Browse files Browse the repository at this point in the history
…op when gets to the end
  • Loading branch information
nemanjagVtool committed May 16, 2024
1 parent d79b934 commit 00366b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/qwik-city/runtime/src/route-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/qwik-city/runtime/src/route-matcher.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
Expand Down

0 comments on commit 00366b9

Please sign in to comment.