]> Cypherpunks repositories - gostls13.git/commitdiff
net/url: normalize scheme to lower case (http not HTTP)
authorRuss Cox <rsc@golang.org>
Thu, 31 Jan 2013 21:45:43 +0000 (13:45 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 31 Jan 2013 21:45:43 +0000 (13:45 -0800)
Also document %2f vs / ambiguity in URL.Path.

Fixes #3913.
Fixes #3659.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7225076

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

index 68f2c2f6e7e176d19f4671dffb7ed5b7be534f2d..667aa0741f275a6d8f3ca7a72b51a24239294a1a 100644 (file)
@@ -220,6 +220,12 @@ func escape(s string, mode encoding) string {
 //
 //     scheme:opaque[?query][#fragment]
 //
+// Note that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.
+// A consequence is that it is impossible to tell which slashes in the Path were
+// slashes in the raw URL and which were %2f. This distinction is rarely important,
+// but when it is a client must use other routines to parse the raw URL or construct
+// the parsed URL. For example, an HTTP server can consult req.RequestURI, and
+// an HTTP client can use URL{Opaque: "/Go%2f"} instead of URL{Path: "/Go/"}.
 type URL struct {
        Scheme   string
        Opaque   string    // encoded opaque data
@@ -371,6 +377,7 @@ func parse(rawurl string, viaRequest bool) (url *URL, err error) {
        if url.Scheme, rest, err = getscheme(rawurl); err != nil {
                goto Error
        }
+       url.Scheme = strings.ToLower(url.Scheme)
 
        rest, url.RawQuery = split(rest, '?', true)
 
index cd3b0b9e8c7a734200dc941687bcc38b68b20020..ed94d020551dee7b6be11531db6c5c369dd2a4a0 100644 (file)
@@ -251,6 +251,15 @@ var urltests = []URLTest{
                },
                "file:///home/adg/rabbits",
        },
+       // case-insensitive scheme
+       {
+               "MaIlTo:webmaster@golang.org",
+               &URL{
+                       Scheme: "mailto",
+                       Opaque: "webmaster@golang.org",
+               },
+               "mailto:webmaster@golang.org",
+       },
 }
 
 // more useful string for debugging than fmt's struct printer