Skip to content

Commit

Permalink
fix: modify normalizePath
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jin-gou committed Jan 29, 2023
1 parent eef368e commit 4563038
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ func normalizePath(dst, src []byte) []byte {

if filepath.Separator == '\\' {
// remove \.\ parts
b = dst
for {
n := bytes.Index(b, strBackSlashDotBackSlash)
if n < 0 {
Expand All @@ -652,7 +651,8 @@ func normalizePath(dst, src []byte) []byte {
if nn < 0 {
nn = 0
}
n += len(strSlashDotDotBackSlash) - 1
nn++
n += len(strSlashDotDotBackSlash)
copy(b[nn:], b[n:])
b = b[:len(b)-n+nn]
}
Expand Down
5 changes: 3 additions & 2 deletions uri_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
package fasthttp

func addLeadingSlash(dst, src []byte) []byte {
// zero length and "C:/" case
if len(src) == 0 || (len(src) > 2 && src[1] != ':') {
// zero length 、"C:/" and "a" case
isDesk := len(src) > 2 && src[1] == ':'
if len(src) == 0 || (!isDesk && src[0] != '/') {
dst = append(dst, '/')
}

Expand Down
8 changes: 8 additions & 0 deletions uri_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ func TestURIPathNormalizeIssue86(t *testing.T) {
var u URI

testURIPathNormalize(t, &u, `C:\a\b\c\fs.go`, `C:\a\b\c\fs.go`)

testURIPathNormalize(t, &u, `a`, `/a`)

testURIPathNormalize(t, &u, "/../../../../../foo", "/foo")

testURIPathNormalize(t, &u, "/..\\..\\..\\..\\..\\", "/")

testURIPathNormalize(t, &u, "/..%5c..%5cfoo", "/foo")
}

0 comments on commit 4563038

Please sign in to comment.