Skip to content

fix(router): match more specific dynamic route when a catch-all was registered first#3880

Open
sanjibani wants to merge 3 commits into
freshframework:mainfrom
sanjibani:fix/router-dynamic-arr-specificity
Open

fix(router): match more specific dynamic route when a catch-all was registered first#3880
sanjibani wants to merge 3 commits into
freshframework:mainfrom
sanjibani:fix/router-dynamic-arr-specificity

Conversation

@sanjibani

Copy link
Copy Markdown

Routes registered via app.route()/app.get() are matched in registration order, so app.route("/blog/[...rest]", A) followed by app.route("/blog/[id]", B) silently shadows B on /blog/foo.

File-system routes are already protected by sortRoutePaths() before insertion; programmatic routes weren't because router.add() pushes to #dynamicArr in command order. Sort #dynamicArr by specificity (static > :param > *) after each push so any later, more specific pattern wins.

Fixes #3861. Added 3 tests covering: catch-all vs :param, :param vs optional, and a unit test for the comparator. All existing 16 router tests still pass.

… link

`https://deno.land/x/fresh/runtime.ts?doc=&s=IS_BROWSER` (404) — the
`deno.land/x/*` docs URL pattern was retired when Deno moved module
documentation to JSR.

Replaced with the canonical JSR module page:
`https://jsr.io/@fresh/core` (200).
…ches win over earlier catch-alls

Routes registered via app.route()/app.get() are matched in registration
order. A catch-all registered before a more specific route silently
shadows it: app.route("/blog/[...rest]", A); app.route("/blog/[id]", B)
never reaches B on /blog/foo.

File-system routes are protected by sortRoutePaths() before insertion;
programmatic routes bypass that step because router.add() pushes in
command order. Sort #dynamicArr by specificity (static > :param > *)
after each insertion so any later, more specific pattern wins.

Closes freshframework#3861.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Programmatic routes via app.route() bypass specificity sorting

1 participant