Skip to content

net/http: ServeMux routes to the wrong handler when routing pattern includes wildcard matching for multiple segments #70652

Closed as not planned
@Loushu

Description

@Loushu

Go version

go version go1.23.3 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/gopher/Library/Caches/go-build'
GOENV='/Users/gopher/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/gopher/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/gopher/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.3'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/gopher/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD=''
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/yw/x8bm5r7s6ss3s7976nd5wyd80000gn/T/go-build415714205=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

When using routing enhancements introduced in go 1.22 and registering a POST and a GET handlers on the same route with a wildcard matching all segments at the end of the route, the router gets confused when processing a request which doesn't have any segments for the wildcard, and calls a handler for the wrong method.
Example:
https://go.dev/play/p/BTJeqbNMFbv

What did you see happen?

2009/11/10 23:00:00 Unexpected GET handler has been called
2009/11/10 23:00:00 Expected status code to be 200, but got 400

What did you expect to see?

I expected a handler for the POST route to be called and to see
"Test passed"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions