aboutsummaryrefslogtreecommitdiff
path: root/uri.go
diff options
context:
space:
mode:
authorGravatar Erik Dubbelboer <erik@dubbelboer.com> 2022-02-28 11:56:59 +0100
committerGravatar Erik Dubbelboer <erik@dubbelboer.com> 2022-02-28 11:56:59 +0100
commit6b5bc7bb304975147b4af68df54ac214ed2554c1 (patch)
tree1f6b828e42e3b3defcdbcd5f54d8fe3e9b48b34c /uri.go
parentDon't log ErrBadTrailer by default (diff)
downloadfasthttp-6b5bc7bb304975147b4af68df54ac214ed2554c1.tar.gz
fasthttp-6b5bc7bb304975147b4af68df54ac214ed2554c1.tar.bz2
fasthttp-6b5bc7bb304975147b4af68df54ac214ed2554c1.zip
Add windows support to normalizePath
This is probably still not 100% sure and there are still many bugs with FS on windows. But it's a slight improvement. Fixes #1226
Diffstat (limited to 'uri.go')
-rw-r--r--uri.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/uri.go b/uri.go
index 62974df..38a431e 100644
--- a/uri.go
+++ b/uri.go
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
+ "path/filepath"
"strconv"
"sync"
)
@@ -634,6 +635,60 @@ func normalizePath(dst, src []byte) []byte {
b = b[:nn+1]
}
+ if filepath.Separator == '\\' {
+ // remove \.\ parts
+ b = dst
+ for {
+ n := bytes.Index(b, strBackSlashDotBackSlash)
+ if n < 0 {
+ break
+ }
+ nn := n + len(strSlashDotSlash) - 1
+ copy(b[n:], b[nn:])
+ b = b[:len(b)-nn+n]
+ }
+
+ // remove /foo/..\ parts
+ for {
+ n := bytes.Index(b, strSlashDotDotBackSlash)
+ if n < 0 {
+ break
+ }
+ nn := bytes.LastIndexByte(b[:n], '/')
+ if nn < 0 {
+ nn = 0
+ }
+ n += len(strSlashDotDotBackSlash) - 1
+ copy(b[nn:], b[n:])
+ b = b[:len(b)-n+nn]
+ }
+
+ // remove /foo\..\ parts
+ for {
+ n := bytes.Index(b, strBackSlashDotDotBackSlash)
+ if n < 0 {
+ break
+ }
+ nn := bytes.LastIndexByte(b[:n], '/')
+ if nn < 0 {
+ nn = 0
+ }
+ n += len(strBackSlashDotDotBackSlash) - 1
+ copy(b[nn:], b[n:])
+ b = b[:len(b)-n+nn]
+ }
+
+ // remove trailing \foo\..
+ n := bytes.LastIndex(b, strBackSlashDotDot)
+ if n >= 0 && n+len(strSlashDotDot) == len(b) {
+ nn := bytes.LastIndexByte(b[:n], '/')
+ if nn < 0 {
+ return append(dst[:0], strSlash...)
+ }
+ b = b[:nn+1]
+ }
+ }
+
return b
}