mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-23 17:27:37 +03:00
Remove '/./' parts from path
This commit is contained in:
@@ -10,6 +10,7 @@ var (
|
||||
strSlash = []byte("/")
|
||||
strSlashSlash = []byte("//")
|
||||
strSlashDotDot = []byte("/..")
|
||||
strSlashDotSlash = []byte("/./")
|
||||
strSlashDotDotSlash = []byte("/../")
|
||||
strCRLF = []byte("\r\n")
|
||||
strHTTP = []byte("http")
|
||||
|
||||
@@ -263,6 +263,17 @@ func normalizePath(dst, src []byte) []byte {
|
||||
b = b[:len(b)-n+nn]
|
||||
}
|
||||
|
||||
// remove /./ parts
|
||||
for {
|
||||
n := bytes.Index(b, strSlashDotSlash)
|
||||
if n < 0 {
|
||||
break
|
||||
}
|
||||
nn := n + len(strSlashDotSlash) - 1
|
||||
copy(b[n:], b[nn:])
|
||||
b = b[:len(b)-nn+n]
|
||||
}
|
||||
|
||||
// remove trailing /foo/..
|
||||
n := bytes.LastIndex(b, strSlashDotDot)
|
||||
if n >= 0 && n+len(strSlashDotDot) == len(b) {
|
||||
|
||||
@@ -71,6 +71,11 @@ func TestURIPathNormalize(t *testing.T) {
|
||||
|
||||
// fake dotdot
|
||||
testURIPathNormalize(t, &u, "/aaa/..bbb/ccc/..", "/aaa/..bbb/")
|
||||
|
||||
// single dot
|
||||
testURIPathNormalize(t, &u, "/a/./b/././c/./d.html", "/a/b/c/d.html")
|
||||
testURIPathNormalize(t, &u, "./foo/", "/foo/")
|
||||
testURIPathNormalize(t, &u, "./../.././../../aaa/bbb/../../../././../", "/")
|
||||
}
|
||||
|
||||
func testURIPathNormalize(t *testing.T, u *URI, requestURI, expectedPath string) {
|
||||
|
||||
Reference in New Issue
Block a user