From 880beafc9f60806597d143b71afd6da226367896 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Tue, 13 Jul 2010 09:21:42 +1000 Subject: [PATCH] http: fix ParseURL to handle //relative_path properly Fixes #900. R=rsc CC=golang-dev https://golang.org/cl/1756042 --- src/pkg/http/url.go | 2 +- src/pkg/http/url_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pkg/http/url.go b/src/pkg/http/url.go index 148ada4b25858..12247ca17b801 100644 --- a/src/pkg/http/url.go +++ b/src/pkg/http/url.go @@ -318,7 +318,7 @@ func ParseURL(rawurl string) (url *URL, err os.Error) { } // Maybe path is //authority/path - if len(path) > 2 && path[0:2] == "//" { + if url.Scheme != "" && len(path) > 2 && path[0:2] == "//" { url.Authority, path = split(path[2:], '/', false) } url.RawPath = path + query diff --git a/src/pkg/http/url_test.go b/src/pkg/http/url_test.go index 3d665100af6ce..097669b9c2ae6 100644 --- a/src/pkg/http/url_test.go +++ b/src/pkg/http/url_test.go @@ -174,6 +174,17 @@ var urltests = []URLTest{ }, "", }, + // leading // without scheme shouldn't create an authority + URLTest{ + "//foo", + &URL{ + Raw: "//foo", + Scheme: "", + RawPath: "//foo", + Path: "//foo", + }, + "", + }, } var urlnofragtests = []URLTest{