Commit fb21bca0 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http, net/url: deal with URL.Opaque beginning with //

Update #4860

R=adg, rsc, campoy
CC=golang-dev
https://golang.org/cl/7369045
parent aed05446
......@@ -353,6 +353,44 @@ var reqWriteTests = []reqWriteTest{
"Host: \r\n" +
"User-Agent: Go http package\r\n\r\n",
},
// Opaque test #1 from golang.org/issue/4860
{
Req: Request{
Method: "GET",
URL: &url.URL{
Scheme: "http",
Host: "www.google.com",
Opaque: "/%2F/%2F/",
},
ProtoMajor: 1,
ProtoMinor: 1,
Header: Header{},
},
WantWrite: "GET /%2F/%2F/ HTTP/1.1\r\n" +
"Host: www.google.com\r\n" +
"User-Agent: Go http package\r\n\r\n",
},
// Opaque test #2 from golang.org/issue/4860
{
Req: Request{
Method: "GET",
URL: &url.URL{
Scheme: "http",
Host: "x.google.com",
Opaque: "//y.google.com/%2F/%2F/",
},
ProtoMajor: 1,
ProtoMinor: 1,
Header: Header{},
},
WantWrite: "GET http://y.google.com/%2F/%2F/ HTTP/1.1\r\n" +
"Host: x.google.com\r\n" +
"User-Agent: Go http package\r\n\r\n",
},
}
func TestRequestWrite(t *testing.T) {
......
......@@ -693,6 +693,10 @@ func (u *URL) RequestURI() string {
if result == "" {
result = "/"
}
} else {
if strings.HasPrefix(result, "//") {
result = u.Scheme + ":" + result
}
}
if u.RawQuery != "" {
result += "?" + u.RawQuery
......
......@@ -798,6 +798,24 @@ var requritests = []RequestURITest{
},
"/a%20b",
},
// golang.org/issue/4860 variant 1
{
&URL{
Scheme: "http",
Host: "example.com",
Opaque: "/%2F/%2F/",
},
"/%2F/%2F/",
},
// golang.org/issue/4860 variant 2
{
&URL{
Scheme: "http",
Host: "example.com",
Opaque: "//other.example.com/%2F/%2F/",
},
"http://other.example.com/%2F/%2F/",
},
{
&URL{
Scheme: "http",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment