-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: double escape of URL #25208
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
This is a question probably better directed to a forum rather than to the issue tracker. See https://golang.org/wiki/Questions . Thanks. |
This is a bug because foo%2Fbar is a valid path as is and does not need to be escaped again. It even passes the internal validEncodedPath check in url.go, but because it does a secondary check of unescaping the path and comparing it to the valid escaped path you get a double escaped path when you should not |
Can you show us a complete program demonstrating the bug? Thanks. CC @bradfitz |
https://play.golang.org/p/DlQWHrX1cuD package main
import (
"fmt"
"net/url"
)
func main() {
expected := "https://httpbin.org/anything/foo%2Fbar/bla"
good, _ := url.Parse(fmt.Sprintf("https://httpbin.org/anything/%s/bla", url.PathEscape("foo/bar")))
bad, _ := url.Parse("https://httpbin.org")
bad.Path = fmt.Sprintf("anything/%s/bla", url.PathEscape("foo/bar"))
alsoBad, _ := url.Parse("https://httpbin.org")
alsoBad.RawPath = fmt.Sprintf("anything/%s/bla", url.PathEscape("foo/bar"))
workAround, _ := url.Parse("https://httpbin.org")
workAround.Path = fmt.Sprintf("anything/%s/bla", url.PathEscape("foo/bar"))
workAround.RawPath = workAround.Path
workAround.Path, _ = url.PathUnescape(workAround.Path)
if expected != good.String() {
fmt.Printf("GOOD: %s != %s", expected, good.String())
}
if expected != bad.String() {
fmt.Printf("BAD: %s != %s\n", expected, bad.String())
}
if expected != alsoBad.String() {
fmt.Printf("ALSO BAD: %s != %s\n", expected, alsoBad.String())
}
if expected != workAround.String() {
fmt.Printf("Worked Around: %s != %s", expected, workAround.String())
}
} |
I think the example doesn't show any bug.
If And the "workAround" is the right way to do this. |
The first example shows
Note that last sentence: "It is an error to set this field in an HTTP client request". And indeed, the net/http code returns an error if it's set. I don't see how that's possible. The sample code as provided seems like it would never happen or wouldn't return the results described. Then the follow-up code shows completely unrelated (and working as expected) code that doesn't involve the RequestURI field. I'm going to close this. If you have a better example of the bug, please post and we can reopen. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
"http://some.example.com/foo%2Fbar"
What did you see instead?
"http://some.example.com/foo%252Fbar"
The text was updated successfully, but these errors were encountered: