Skip to content

Commit fb21bca

Browse files
committed
net/http, net/url: deal with URL.Opaque beginning with //
Update #4860 R=adg, rsc, campoy CC=golang-dev https://golang.org/cl/7369045
1 parent aed0544 commit fb21bca

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/pkg/net/http/requestwrite_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,44 @@ var reqWriteTests = []reqWriteTest{
353353
"Host: \r\n" +
354354
"User-Agent: Go http package\r\n\r\n",
355355
},
356+
357+
// Opaque test #1 from golang.org/issue/4860
358+
{
359+
Req: Request{
360+
Method: "GET",
361+
URL: &url.URL{
362+
Scheme: "http",
363+
Host: "www.google.com",
364+
Opaque: "/%2F/%2F/",
365+
},
366+
ProtoMajor: 1,
367+
ProtoMinor: 1,
368+
Header: Header{},
369+
},
370+
371+
WantWrite: "GET /%2F/%2F/ HTTP/1.1\r\n" +
372+
"Host: www.google.com\r\n" +
373+
"User-Agent: Go http package\r\n\r\n",
374+
},
375+
376+
// Opaque test #2 from golang.org/issue/4860
377+
{
378+
Req: Request{
379+
Method: "GET",
380+
URL: &url.URL{
381+
Scheme: "http",
382+
Host: "x.google.com",
383+
Opaque: "//y.google.com/%2F/%2F/",
384+
},
385+
ProtoMajor: 1,
386+
ProtoMinor: 1,
387+
Header: Header{},
388+
},
389+
390+
WantWrite: "GET http://y.google.com/%2F/%2F/ HTTP/1.1\r\n" +
391+
"Host: x.google.com\r\n" +
392+
"User-Agent: Go http package\r\n\r\n",
393+
},
356394
}
357395

358396
func TestRequestWrite(t *testing.T) {

src/pkg/net/url/url.go

+4
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,10 @@ func (u *URL) RequestURI() string {
693693
if result == "" {
694694
result = "/"
695695
}
696+
} else {
697+
if strings.HasPrefix(result, "//") {
698+
result = u.Scheme + ":" + result
699+
}
696700
}
697701
if u.RawQuery != "" {
698702
result += "?" + u.RawQuery

src/pkg/net/url/url_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,24 @@ var requritests = []RequestURITest{
798798
},
799799
"/a%20b",
800800
},
801+
// golang.org/issue/4860 variant 1
802+
{
803+
&URL{
804+
Scheme: "http",
805+
Host: "example.com",
806+
Opaque: "/%2F/%2F/",
807+
},
808+
"/%2F/%2F/",
809+
},
810+
// golang.org/issue/4860 variant 2
811+
{
812+
&URL{
813+
Scheme: "http",
814+
Host: "example.com",
815+
Opaque: "//other.example.com/%2F/%2F/",
816+
},
817+
"http://other.example.com/%2F/%2F/",
818+
},
801819
{
802820
&URL{
803821
Scheme: "http",

0 commit comments

Comments
 (0)