]> Cypherpunks repositories - gostls13.git/commitdiff
net/http, net/url: deal with URL.Opaque beginning with //
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 21 Feb 2013 20:01:47 +0000 (12:01 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 21 Feb 2013 20:01:47 +0000 (12:01 -0800)
Update #4860

R=adg, rsc, campoy
CC=golang-dev
https://golang.org/cl/7369045

src/pkg/net/http/requestwrite_test.go
src/pkg/net/url/url.go
src/pkg/net/url/url_test.go

index 3a5cd8ae2de1c84f8ce91b109baabd2ada927589..bc637f18b0c2f95356e2ac077e149ce9bef4605e 100644 (file)
@@ -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) {
index 667aa0741f275a6d8f3ca7a72b51a24239294a1a..9c08b35ba8f4facfc8f3f915ce1c56ae27d8b3fe 100644 (file)
@@ -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
index ed94d020551dee7b6be11531db6c5c369dd2a4a0..4c4f406c2159f774a2739fcfef40fcdfd52d04c7 100644 (file)
@@ -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",