Repository navigation
tree: collapse consecutive subrouter wildcards in Walk - #1240
Open
NgoQuocViet2001 wants to merge 1 commit into
Open
NgoQuocViet2001 wants to merge 1 commit into
NgoQuocViet2001 wants to merge 1 commit into
Conversation
Walk joined the parent route and pattern and removed "/*/" with a single
strings.ReplaceAll. When two subrouter wildcards are adjacent, for example
a Route("/") or Mount("/") directly inside another subrouter, the joined
path contains "/*/*/" and one "/*/" survives because ReplaceAll does not
match overlapping occurrences. Walk then reported paths such as
"/v1/resources/*/{resource_id}" while RoutePattern() gives
"/v1/resources/{resource_id}".
Reuse replaceWildcards, which RoutePattern() already uses, so the
connector is removed until none remain.
agammann
approved these changes
Nov 1, 2026
agammann
left a comment
There was a problem hiding this comment.
The route pattern normalization now uses the same iterative helper as Context.RoutePattern, so adjacent subrouter connectors are removed while a terminal catch-all remains. I checked the three regression layouts in TestWalkConsecutiveSubrouterWildcards and ran both that test and the full root package on this head; both pass.
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.
Walk removes the internal "//" subrouter connector with a single strings.ReplaceAll, which misses overlapping matches. When a Route("/") or Mount("/") sits directly inside another subrouter (the layout in the TestRoutePattern comment), the joined path has "///" and one "//" survives. Walk then disagrees with RoutePattern(), r.Pattern and Mux.Find:
This makes walk() use replaceWildcards, which RoutePattern() has used for this since #515, so the two agree. A trailing "/*" from a real catch-all is kept. See also #310.
go test ./...(root and middleware) passes;go vet . ./middlewareandgofmt -l .are clean.