Repository navigation
Conversation
A regexp placeholder with a non-slash tail could span path segments. For a
pattern like /re/{name:[^.]+}.json the segment-end delimiter chi uses is
the first byte of the suffix ('.'), not '/'. If the user's regexp did not
itself exclude '/', the capture could include one: /re/a/b.json matched
with name="a/b". The URL-patterns contract says a placeholder value will
never contain '/', so chi must enforce that regardless of what the user
regexp allows. The ntParam path already does this check.
Apply the same cross-segment guard to the ntRegexp branch after a
successful regexp match: skip the node if xsearch[:p] contains a '/'.
Regression test TestMuxRegexpPlaceholderWithSuffixDoesNotMatchSlash
confirms /re/a.json still matches (name="a") while /re/a/b.json 404s,
and a plain placeholder with suffix 404s on the same input for parity.
Fixes go-chi#1188.
piyush295
force-pushed
the
fix/regexp-placeholder-no-slash
branch
from
October 16, 2026 09:26
9600d50 to
99ea9fd
Compare
This branch has not been deployed
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.
Bug (fixes #1188)
A regexp placeholder with a non-slash tail could span path segments. For a pattern like
/re/{name:[^.]+}.json, the segment-end delimiter chi uses is the first byte of the suffix (.), not/. If the user's regexp did not itself exclude/, the capture could include one:The "URL patterns" documentation in
chi.gosays of a regexp placeholder that/will never match. ThentParambranch already enforces this with astrings.IndexByte(xsearch[:p], '/') != -1check. ThentRegexpbranch didn't.Fix
After a successful regexp match in the
ntRegexpbranch, apply the same cross-segment guard: if the matched substring contains a/, skip the node. This holds the public contract regardless of what the user regexp allows.Test
TestMuxRegexpPlaceholderWithSuffixDoesNotMatchSlashregisters both/re/{name:[^.]+}.jsonand/plain/{name}.jsonand asserts:/re/a.json→name="a",/plain/a.json→name="a")./re/a/b.json,/plain/a/b.json).go test ./...passes (both chi and chi/middleware).