diff --git a/uri.go b/uri.go index 464ccd7..6249f44 100644 --- a/uri.go +++ b/uri.go @@ -268,12 +268,7 @@ func (u *URI) parse(host, uri []byte, h *RequestHeader) { func normalizePath(dst, src []byte) []byte { dst = dst[:0] - - // add leading slash - if len(src) == 0 || src[0] != '/' { - dst = append(dst, '/') - } - + dst = addLeadingSlash(dst, src) dst = decodeArgAppend(dst, src, false) // remove duplicate slashes diff --git a/uri_unix.go b/uri_unix.go new file mode 100644 index 0000000..631712a --- /dev/null +++ b/uri_unix.go @@ -0,0 +1,15 @@ +// +build !windows + +package fasthttp + +import "bytes" + + +func addLeadingSlash(dst, src []byte) []byte { + // add leading slash for unix paths + if len(src) == 0 || src[0] != '/' { + dst = append(dst, '/') + } + + return dst +} diff --git a/uri_windows.go b/uri_windows.go new file mode 100644 index 0000000..c7980c8 --- /dev/null +++ b/uri_windows.go @@ -0,0 +1,12 @@ +// +build windows + +package fasthttp + +func addLeadingSlash(dst, src []byte) []byte { + // zero length and "C:/" case + if len(src) == 0 || (len(src) > 2 && src[1] != ':') { + dst = append(dst, '/') + } + + return dst +} \ No newline at end of file diff --git a/uri_windows_test.go b/uri_windows_test.go new file mode 100644 index 0000000..61d1a2c --- /dev/null +++ b/uri_windows_test.go @@ -0,0 +1,12 @@ +// +build windows + +package fasthttp + +import "testing" + +func TestURIPathNormalizeIssue86(t *testing.T) { + // see https://github.com/valyala/fasthttp/issues/86 + var u URI + + testURIPathNormalize(t, &u, `C:\a\b\c\fs.go`, `C:\a\b\c\fs.go`) +}