Skip to content

Commit

Permalink
Git commit fix URI parse for urls like host.dm?some/path/to/file (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpikulik committed Aug 21, 2020
1 parent 434c48b commit aa3f96c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions uri.go
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions uri_test.go
Expand Up @@ -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) {
Expand Down

0 comments on commit aa3f96c

Please sign in to comment.