Git commit fix URI parse for urls like host.dm?some/path/to/file (#866)

This commit is contained in:
Vitali Pikulik
2020-08-21 16:21:23 +02:00
committed by GitHub
parent 434c48ba7e
commit aa3f96c883
2 changed files with 11 additions and 3 deletions
+7 -3
View File
@@ -575,11 +575,15 @@ func splitHostURI(host, uri []byte) ([]byte, []byte, []byte) {
n += len(strSlashSlash)
uri = uri[n:]
n = bytes.IndexByte(uri, '/')
if n < 0 {
nq := bytes.IndexByte(uri, '?')
if nq >= 0 && nq < n {
// A hack for urls like foobar.com?a=b/xyz
n = nq
} else if n < 0 {
// A hack for bogus urls like foobar.com?a=b without
// slash after host.
if n = bytes.IndexByte(uri, '?'); n >= 0 {
return scheme, uri[:n], uri[n:]
if nq >= 0 {
return scheme, uri[:nq], uri[nq:]
}
return scheme, uri, strSlash
}
+4
View File
@@ -283,6 +283,10 @@ func TestURIParseNilHost(t *testing.T) {
// missing slash after hostname
testURIParseScheme(t, "http://foobar.com?baz=111", "http", "foobar.com", "/?baz=111", "")
// slash in args
testURIParseScheme(t, "http://foobar.com?baz=111/222/xyz", "http", "foobar.com", "/?baz=111/222/xyz", "")
testURIParseScheme(t, "http://foobar.com?111/222/xyz", "http", "foobar.com", "/?111/222/xyz", "")
}
func testURIParseScheme(t *testing.T, uri, expectedScheme, expectedHost, expectedRequestURI, expectedHash string) {