mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-25 17:45:28 +03:00
Fix parsing relative URLs starting with // (#702)
* Fix parsing relative URLs starting with // * Improve test
This commit is contained in:
@@ -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...)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user