Skip to content

net/http: ServeMux not backwards compatible (with Go 1.21) when registering double-slash patterns #69044

Closed
@rivo

Description

@rivo

What version of Go are you using (go version)?

$ go version
go version go1.23.0 darwin/arm64

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 of one slash (go1.21): https://go.dev/play/p/mmC95m4W4ko)

What did you expect to see?

Running request...
200 OK
one slash

What did you see instead?

Running request...
301 Moved Permanently
<a href="/test/">Moved Permanently</a>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions