-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: ServeMux not backwards compatible (with Go 1.21) when registering double-slash patterns #69044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
http.ServeMux
not backwards compatible when registering double-slash patterns
As you have read, https://go.dev/doc/go1.22#enhanced_routing_patterns mentions
Have you tried setting cc @neild for whether this incompatibility is intended. |
Just tried that. Yes, it reverts it back to the pre go1.22 result. So I guess maybe this was intended? @cherrymui / @nild feel free to close this one if there's nothing unexpected here. |
Subtly I wonder if A function Specifically a comment suggests:
For registration, the serveMux method In contrast, for matching, the The |
@rivo This particular incompatibility wasn't intended, but is covered by the caveat that Cherry quoted, and the GODEBUG setting is the right fix. Closing as WAI. |
What version of Go are you using (
go version
)?but the issue appears with go1.22 already, when enhanced routing patterns were introduced.
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?This has been confirmed on multiple architectures.
What did you do?
I'm registering two
http.Handler
's, one with the pattern"/"
(one slash) and the other with the pattern"//"
(two slashes). See the following example code:https://go.dev/play/p/Gv6F8CMxant
Before go1.22, requesting a URI such as
/abc
would invoke the one-slash handler. Since go1.22, the same URI invokes the two-slash handler. In fact, due to trailing-slash redirection, now a request for/abc
is redirected to/abc/
, which did not happen in go1.21.I realize that such a pattern (
"//"
) does not make much sense. And specifying"GET //"
will lead to a panic. But nonetheless, this compatibility change broke our software when upgrading to go1.22. We'll be fine with a "won't fix" in any case but I thought it is relevant enough to open an issue for it. Maybe it will reveal other issues with the enhanced routing patterns.(The following playground will follow the redirect and output
two slashes
(go1.22) instead ofone slash
(go1.21): https://go.dev/play/p/mmC95m4W4ko)What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: