mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-13 15:46:49 +03:00
Issue #86: Fixed leading slash on Windows
This commit is contained in:
@@ -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
|
||||
|
||||
+15
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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`)
|
||||
}
|
||||
Reference in New Issue
Block a user