fix(router): match more specific dynamic route when a catch-all was registered first#3880
Open
sanjibani wants to merge 3 commits into
Open
fix(router): match more specific dynamic route when a catch-all was registered first#3880sanjibani wants to merge 3 commits into
sanjibani wants to merge 3 commits into
Conversation
… 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).
… jsr.io/@fresh/core
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.