diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2021-10-01 13:33:42 +0200 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2021-10-01 13:38:31 +0200 |
commit | 542a203b42a3cb722244e1ef74fda0804a926383 (patch) | |
tree | 5690b21323c3ae6a779603e4ac3a21c1bada9a85 /uri_test.go | |
parent | feat: improve TCPDialer by `sync.map` instead of `map+mutex` (#1106) (diff) | |
download | fasthttp-542a203b42a3cb722244e1ef74fda0804a926383.tar.gz fasthttp-542a203b42a3cb722244e1ef74fda0804a926383.tar.bz2 fasthttp-542a203b42a3cb722244e1ef74fda0804a926383.zip |
Properly parse URI
Use URI parse code based on net/uri to validate hostnames.
Diffstat (limited to 'uri_test.go')
-rw-r--r-- | uri_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/uri_test.go b/uri_test.go index c56c14e..481b51a 100644 --- a/uri_test.go +++ b/uri_test.go @@ -365,6 +365,18 @@ func TestURIParse(t *testing.T) { testURIParse(t, &u, "", "//aaa.com\r\n\r\nGET x", "http:///", "", "/", "", "", "") + + testURIParse(t, &u, "", "http://[fe80::1%25en0]/", + "http://[fe80::1%en0]/", "[fe80::1%en0]", "/", "/", "", "") + + testURIParse(t, &u, "", "http://[fe80::1%25en0]:8080/", + "http://[fe80::1%en0]:8080/", "[fe80::1%en0]:8080", "/", "/", "", "") + + testURIParse(t, &u, "", "http://hello.世界.com/foo", + "http://hello.世界.com/foo", "hello.世界.com", "/foo", "/foo", "", "") + + testURIParse(t, &u, "", "http://hello.%e4%b8%96%e7%95%8c.com/foo", + "http://hello.世界.com/foo", "hello.世界.com", "/foo", "/foo", "", "") } func testURIParse(t *testing.T, u *URI, host, uri, @@ -404,3 +416,14 @@ func TestURIWithQuerystringOverride(t *testing.T) { t.Fatalf("Expected Querystring to be overridden but was %s ", uriString) } } + +func TestInvalidUrl(t *testing.T) { + url := `https://.çèéà@&~!&:=\\/\"'~<>|+-*()[]{}%$;,¥&&$22|||<>< 4ly8lzjmoNx233AXELDtyaFQiiUH-fd8c-CnXUJVYnGIs4Uwr-bptom5GCnWtsGMQxeM2ZhoKE973eKgs2Sjh6RePnyaLpCi6SiNSLevcMoraARrp88L-SgtKqd-XHAtSI8hiPRiXPQmDIA4BGhSgoc0nfn1PoYuGKKmDcZ04tANRc3iz4aF4-A1UrO8bLHTH7MEJvzx.someqa.fr/A/?&QS_BEGIN<&8{b'Ob=p*f> QS_END` + + u := AcquireURI() + defer ReleaseURI(u) + + if err := u.Parse(nil, []byte(url)); err == nil { + t.Fail() + } +} |