Skip to content

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

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

Open
FiloSottile opened this issue May 13, 2025 · 2 comments
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@FiloSottile
Copy link
Contributor

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

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label May 13, 2025
@mknyszek
Copy link
Contributor

CC @jba @neild

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 13, 2025
@mknyszek mknyszek added this to the Backlog milestone May 13, 2025
@jba jba self-assigned this May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants