Fix parsing relative URLs starting with // (#702)

* Fix parsing relative URLs starting with //

* Improve test
This commit is contained in:
Erik Dubbelboer
2019-12-01 09:44:21 +01:00
committed by GitHub
parent 39dd1045bb
commit 6cccaebf64
2 changed files with 14 additions and 3 deletions
+8 -3
View File
@@ -263,9 +263,14 @@ func (u *URI) Parse(host, uri []byte) {
func (u *URI) parse(host, uri []byte, isTLS bool) {
u.Reset()
scheme, host, uri := splitHostURI(host, uri)
u.scheme = append(u.scheme, scheme...)
lowercaseBytes(u.scheme)
if len(host) == 0 || bytes.Contains(uri, strColonSlashSlash) {
scheme, newHost, newURI := splitHostURI(host, uri)
u.scheme = append(u.scheme, scheme...)
lowercaseBytes(u.scheme)
host = newHost
uri = newURI
}
if isTLS {
u.scheme = append(u.scheme[:0], strHTTPS...)
}
+6
View File
@@ -345,6 +345,12 @@ func TestURIParse(t *testing.T) {
// http:// in query params
testURIParse(t, &u, "aaa.com", "/foo?bar=http://google.com",
"http://aaa.com/foo?bar=http://google.com", "aaa.com", "/foo", "/foo", "bar=http://google.com", "")
testURIParse(t, &u, "aaa.com", "//relative",
"http://aaa.com/relative", "aaa.com", "/relative", "//relative", "", "")
testURIParse(t, &u, "", "//aaa.com//absolute",
"http://aaa.com/absolute", "aaa.com", "/absolute", "//absolute", "", "")
}
func testURIParse(t *testing.T, u *URI, host, uri,