Skip to content

net/http: ServeMux.Handler returns wrong pattern with trailing-slash redirection handler #73688

Closed
@FiloSottile

Description

@FiloSottile

ServeMux.Handler should return patterns as passed to Handle.

However, if returning a trailing-slash redirection handler (but not if returning a request sanitizing redirection handler), non-... wildcards are replaced with the corresponding segment from the path.

The following code

mux := http.NewServeMux()
mux.Handle("/{x}/", http.NotFoundHandler())
r, _ := http.NewRequest("POST", "/foo", nil)
_, p := mux.Handler(r)
fmt.Println(p)

prints /foo/ instead of /{x}/.

https://go.dev/play/p/XQjZOXTLVTQ

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.NeedsFixThe path to resolution is known, but the work has not been done.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions