From 7b4520aa0180799552b48e9df885962b55d43c44 Mon Sep 17 00:00:00 2001 From: Vitaly Pikulik Date: Thu, 20 Aug 2020 13:20:55 +0200 Subject: [PATCH] Git commit fix URI parse for urls like host.dm?some/path/to/file --- uri.go | 10 +++++++--- uri_test.go | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/uri.go b/uri.go index 695efe42c0..0650c930d1 100644 --- a/uri.go +++ b/uri.go @@ -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 } diff --git a/uri_test.go b/uri_test.go index 0a59db5907..cebaa73521 100644 --- a/uri_test.go +++ b/uri_test.go @@ -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) {