mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Git commit fix URI parse for urls like host.dm?some/path/to/file (#866)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user