Repository navigation
keep matching other patterns when the last segment is a bare verb - #7539
Merged
johanbrandhorst merged 1 commit intoOct 19, 2026
Merged
Conversation
johanbrandhorst
approved these changes
Oct 19, 2026
cvas22
force-pushed
the
fix-bare-verb-routing
branch
from
October 19, 2026 04:31
8283e84 to
b9b1e53
Compare
Contributor
Author
|
Rebased and resolved merge conflict. |
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.
References to other Issues or PRs
None. This is a follow-up to #1947, which introduced the current check.
Have you read the Contributing Guidelines?
Yes
Brief description of what is fixed or changed
When the last path segment is just a pattern's verb with nothing before it (e.g.
GET /v1/:cancel),ServeMux.ServeHTTPreturned 404 as soon as it reached a handler whose pattern has that verb. It didn't go on to check the remaining handlers. Handlers are checked newest-first, so the outcome depended on registration order:Before #1947 this was a global up-front check: any last segment starting with
:got a 404. #1947 moved it into the per-handler loop. Since then it only fires for some patterns, and only if one of them is reached first. The method-fallback loop below it has no such check at all.A pattern with a verb can't match an empty segment before the verb, so this PR skips that handler (
continue) instead of ending the search. The result no longer depends on registration order, and the two loops behave the same. When no other pattern matches, the request still ends in a 404.TestServeMux_BareVerbDoesNotDependOnRegistrationOrdercovers both registration orders and the only-verb-pattern case. The order-dependent case fails onmain.Other comments