Skip to content
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

net/url: resolvePath should not collapse leading slashes in the path component #21158

Closed
marktheunissen opened this issue Jul 25, 2017 · 3 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@marktheunissen
Copy link
Contributor

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

master

What operating system and processor architecture are you using (go env)?

darwin/amd64

What did you do?

Using Go's net/http DefaultClient, make a GET request that returns a redirect to a fully formed Location URI.

GET /foo
Host: example.com
HTTP/1.1 301 Moved Permanently
Location: http://example.com//foo/bar

What did you expect to see?

The http.Client should redirect tohttp://example.com//foo/bar, as instructed by the Location header.

What did you see instead?

The http.Client redirected to http://example.com/foo/bar, which is a cleaned-up URL, with a single slash instead of double.

The http.Client.Do() code is using req.URL.Parse() on the Location header here: https://github.com/golang/go/blob/master/src/net/http/client.go#L529-L538

Behaviour of other clients

curl will use the Location header byte-for-byte, and correctly redirect to the double-slash:

$ curl -Lv http://example.com/foo
> GET /foo
...
< HTTP/1.1 301 Moved Permanently
< Location: http://example.com//foo/bar
...
* Issue another request to this URL: 'http://example.com//foo/bar'
...
> GET //foo/bar HTTP/1.1

Playground

Here is an example of the incorrect behavior:

https://play.golang.org/p/ZgPpXddu2G

@marktheunissen
Copy link
Contributor Author

@gopherbot
Copy link

CL https://golang.org/cl/51050 mentions this issue.

@ALTree ALTree added this to the Go1.10 milestone Jul 25, 2017
@ALTree ALTree added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jul 25, 2017
@rsc
Copy link
Contributor

rsc commented Oct 30, 2017

If I make the example be https://play.golang.org/p/NNfbZF_Yd_ with the URL being example.com//foo//bar, we preserve the second //; we should preserve the first too. This is just a bug on my part. I probably wrote the code using strings.TrimLeft before strings.TrimPrefix existed, and I was lazy. Thanks for fixing it.

@golang golang locked and limited conversation to collaborators Oct 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

4 participants