Skip to content

Commit f4dd317

Browse files
committed
fix: ignore path name case on windows platform
1 parent 2b66b85 commit f4dd317

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

src/param/cli.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ func doParseCli() []*Param {
191191
param.AccessLog, _ = result.GetString("accesslog")
192192
param.ErrorLog, _ = result.GetString("errorlog")
193193

194+
// root
195+
root, _ := result.GetString("root")
196+
root, _ = normalizeFsPath(root)
197+
param.Root = root
198+
194199
// certificate
195200
key, _ := result.GetString("key")
196201
cert, _ := result.GetString("cert")

src/param/util.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ func normalizeUrlPaths(inputs []string) []string {
5858
return outputs
5959
}
6060

61+
func asciiToLowerCase(input string) string {
62+
buffer := []byte(input)
63+
length := len(buffer)
64+
65+
for i := 0; i < length; {
66+
r, w := utf8.DecodeRune(buffer[i:])
67+
if w == 1 && r >= 'A' && r <= 'Z' {
68+
buffer[i] += 'a' - 'A'
69+
}
70+
71+
i += w
72+
}
73+
74+
return string(buffer)
75+
}
76+
77+
func normalizeFsPath(input string) (string, error) {
78+
abs, err := filepath.Abs(input)
79+
if err != nil {
80+
return abs, err
81+
}
82+
83+
volume := filepath.VolumeName(abs)
84+
if len(volume) > 0 {
85+
// suppose on windows platform, ignore ascii case in path name
86+
abs = asciiToLowerCase(abs)
87+
}
88+
89+
return abs, err
90+
}
91+
6192
func normalizeFsPaths(inputs []string) []string {
6293
outputs := make([]string, 0, len(inputs))
6394

@@ -66,7 +97,7 @@ func normalizeFsPaths(inputs []string) []string {
6697
continue
6798
}
6899

69-
abs, err := filepath.Abs(input)
100+
abs, err := normalizeFsPath(input)
70101
if err != nil {
71102
continue
72103
}

src/param/util_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package param
2+
3+
import "testing"
4+
5+
func TestAsciiToLowerCase(t *testing.T) {
6+
str := "Hello, 你好"
7+
lower := asciiToLowerCase(str)
8+
expect := "hello, 你好"
9+
if lower != expect {
10+
t.Error(lower)
11+
}
12+
}

src/serverHandler/responseData.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (h *handler) getResponseData(r *http.Request) (data *responseData) {
290290

291291
reqFsPath, _absErr := filepath.Abs(h.root + reqPath)
292292
if _absErr != nil {
293-
reqFsPath = path.Clean(h.root + reqPath)
293+
reqFsPath = filepath.Clean(h.root + reqPath)
294294
}
295295

296296
file, item, _statErr := stat(reqFsPath, !h.emptyRoot)

0 commit comments

Comments
 (0)