Skip to content

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

@marktheunissen

Description

@marktheunissen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions