Issue #86: Fixed leading slash on Windows

This commit is contained in:
Aleksandr Razumov
2016-05-04 10:07:11 +03:00
parent 3509bd8a7d
commit 5e1bdcae2d
4 changed files with 40 additions and 6 deletions
+1 -6
View File
@@ -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
View File
@@ -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
}
+12
View File
@@ -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
}
+12
View File
@@ -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`)
}