Skip to content

Commit

Permalink
Fixes router looping for specific request path for routes with more o…
Browse files Browse the repository at this point in the history
…ptional parameters
  • Loading branch information
jan.kucera committed Aug 1, 2024
1 parent c70a7db commit e40b81a
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 12 deletions.
13 changes: 3 additions & 10 deletions packages/core/src/router/StaticRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,12 @@ export class StaticRoute extends AbstractRoute<string> {
const pattern = optionalParams.reduce((path, paramExpr, idx, matches) => {
const lastIdx = matches.length - 1;
const hasSlash = paramExpr.substr(0, 2) === '\\/';
const separator = hasSlash ? '/' : '';

let separator = '';

if (idx === 0) {
separator = '(?:' + (hasSlash ? '/' : '');
} else {
separator = hasSlash ? '/?' : '';
}

let regExpr = separator + `([^/?]+)?(?=/|$)?`;
let regExpr = '(?:' + separator + `([^/?]+)(?=/|$))?`;

if (idx === lastIdx) {
regExpr += ')?';
regExpr += '';
}

return path.replace(paramExpr, regExpr);
Expand Down
Loading

0 comments on commit e40b81a

Please sign in to comment.