aboutsummaryrefslogtreecommitdiff
path: root/uri_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-10-22 17:50:47 +0300
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-10-22 17:50:47 +0300
commitffc2b7025d239521a4188a829ee006a723ccdc3c (patch)
tree419ee06b41d6d1ca325e787cd80bebff7cc87742 /uri_test.go
parentDo not encode dot in args (diff)
downloadfasthttp-ffc2b7025d239521a4188a829ee006a723ccdc3c.tar.gz
fasthttp-ffc2b7025d239521a4188a829ee006a723ccdc3c.tar.bz2
fasthttp-ffc2b7025d239521a4188a829ee006a723ccdc3c.zip
Added URI path normalization, i.e. //foo//../bar converts to /foo/bar
Diffstat (limited to 'uri_test.go')
-rw-r--r--uri_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/uri_test.go b/uri_test.go
index 2ad5068..423cfaa 100644
--- a/uri_test.go
+++ b/uri_test.go
@@ -5,6 +5,55 @@ import (
"testing"
)
+func TestURIPathNormalize(t *testing.T) {
+ var u URI
+
+ // double slash
+ testURIPathNormalize(t, &u, "/aa//bb", "/aa/bb")
+
+ // triple slash
+ testURIPathNormalize(t, &u, "/x///y/", "/x/y/")
+
+ // multi slashes
+ testURIPathNormalize(t, &u, "/abc//de///fg////", "/abc/de/fg/")
+
+ // encoded slashes
+ testURIPathNormalize(t, &u, "/xxxx%2fyyy%2f%2F%2F", "/xxxx/yyy/")
+
+ // dotdot
+ testURIPathNormalize(t, &u, "/aaa/..", "/")
+
+ // dotdot with trailing slash
+ testURIPathNormalize(t, &u, "/xxx/yyy/../", "/xxx/")
+
+ // multi dotdots
+ testURIPathNormalize(t, &u, "/aaa/bbb/ccc/../../ddd", "/aaa/ddd")
+
+ // dotdots separated by other data
+ testURIPathNormalize(t, &u, "/a/b/../c/d/../e/..", "/a/c/")
+
+ // too many dotdots
+ testURIPathNormalize(t, &u, "/aaa/../../../../xxx", "/xxx")
+ testURIPathNormalize(t, &u, "/../../../../../..", "/")
+ testURIPathNormalize(t, &u, "/../../../../../../", "/")
+
+ // encoded dotdots
+ testURIPathNormalize(t, &u, "/aaa%2Fbbb%2F%2E.%2Fxxx", "/aaa/xxx")
+
+ // double slash with dotdots
+ testURIPathNormalize(t, &u, "/aaa////..//b", "/b")
+
+ // fake dotdot
+ testURIPathNormalize(t, &u, "/aaa/..bbb/ccc/..", "/aaa/..bbb/")
+}
+
+func testURIPathNormalize(t *testing.T, u *URI, requestURI, expectedPath string) {
+ u.Parse(nil, []byte(requestURI))
+ if string(u.Path) != expectedPath {
+ t.Fatalf("Unexpected path %q. Expected %q. requestURI=%q", u.Path, expectedPath, requestURI)
+ }
+}
+
func TestURIAppendBytes(t *testing.T) {
var args Args