Repository navigation
feat: add Template.MODE_STARTS_WITH_SEGMENT matching mode - #1565
Merged
Merged
Conversation
jlouvel
commented
Oct 25, 2026
jlouvel
left a comment
Collaborator
Author
There was a problem hiding this comment.
@thboileau Could you review this enhancement?
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The post-match boundary check prevents regex backtracking to an earlier valid boundary, causing both match() and parse() to reject valid URI prefixes.
1 open issue
What changed in this PR
Adds an opt-in segment-aware prefix matching mode to Restlet’s URI templates, addressing #1564 without changing existing routing defaults.
Changes:
- Introduces
MODE_STARTS_WITH_SEGMENTwith shared matching logic formatch()andparse(). - Adds template boundary, variable parsing, and nested-router tests.
- Documents the new mode in the changelog.
| File | Description |
|---|---|
org.restlet/src/test/java/org/restlet/routing/TemplateTestCase.java |
Tests boundaries, parsing, and existing prefix behavior. |
org.restlet/src/test/java/org/restlet/routing/RouterTestCase.java |
Tests segment-aware mounts and root fallback. |
org.restlet/src/main/java/org/restlet/routing/Template.java |
Adds the mode and shared boundary-checking logic. |
changes.md |
Records the new matching mode and its routing use case. |
Review effort: Balanced
Like MODE_STARTS_WITH, but the match must end on a URI path segment boundary (end of string, '/', '?', ';' or '#', or a match ending with '/'). A route attached to /mcp then matches /mcp, /mcp/tools and /mcp?x=1 but not /mcpx, which makes it safe to mount several routers or applications under path prefixes on one connector. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Check the segment boundary inside the regex instead of after
lookingAt(), so a greedy variable can backtrack to an earlier valid
boundary, as in "/files/{name}.json" matching "/files/a.json;b.jsonx".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jerome Louvel <374450+jlouvel@users.noreply.github.com>
jlouvel
force-pushed
the
feat/template-segment-matching
branch
from
October 31, 2026 22:02
2587eaf to
d484423
Compare
|
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.




Closes #1564.
Adds
Template.MODE_STARTS_WITH_SEGMENT: likeMODE_STARTS_WITH, but the match must end on a URI path segment boundary, meaning the end of the string, a following/,?,;or#, or a match that itself ends with/. A route attached to/mcpthen matches/mcp,/mcp/toolsand/mcp?x=1, but not/mcpxor/mcp-admin/tools.Changes
Template: new constant, and a privatematches()used by bothmatch()andparse(), so scoring and parsing agree.MODE_EQUALSandMODE_STARTS_WITHbehave as before.TemplateTestCase: boundaries (/,?,;,#, end of string), a template ending with/, an empty template, variable parsing, and a check thatMODE_STARTS_WITHstill matches by character.RouterTestCase: catch-all routers mounted at/mcp,/mcp-adminand the root, with/mcpxfalling through to the root.changes.md: entry under 3.0 Milestone 2, Enhancements.Validation
./mvnw -B -pl org.restlet verify: 2,222 tests passed, 0 failures. Spotless, JaCoCo and SpotBugs checks are met (8 findings, under the existing threshold of 9).Not included
Making this the default mode for
RouterandDirectorytargets would change behaviour for existing applications. The issue raises that as an open question.