Skip to content

Commit

Permalink
net/url: normalize scheme to lower case (http not HTTP)
Browse files Browse the repository at this point in the history
Also document %2f vs / ambiguity in URL.Path.

Fixes #3913.
Fixes #3659.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7225076
  • Loading branch information
rsc committed Jan 31, 2013
1 parent d314e3a commit 4085426
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/pkg/net/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions src/pkg/net/url/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ var urltests = []URLTest{
},
"file:///home/adg/rabbits",
},
// case-insensitive scheme
{
"MaIlTo:[email protected]",
&URL{
Scheme: "mailto",
Opaque: "[email protected]",
},
"mailto:[email protected]",
},
}

// more useful string for debugging than fmt's struct printer
Expand Down

0 comments on commit 4085426

Please sign in to comment.