File tree Expand file tree Collapse file tree 6 files changed +40
-37
lines changed Expand file tree Collapse file tree 6 files changed +40
-37
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package param
33import (
44 "../goNixArgParser"
55 "../serverErrHandler"
6+ "../util"
67 "errors"
78 "fmt"
89 "io/ioutil"
@@ -193,7 +194,7 @@ func doParseCli() []*Param {
193194
194195 // root
195196 root , _ := result .GetString ("root" )
196- root , _ = normalizeFsPath (root )
197+ root , _ = util . NormalizeFsPath (root )
197198 param .Root = root
198199
199200 // certificate
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package param
33import (
44 "../util"
55 "path"
6- "path/filepath"
76 "strings"
87 "unicode/utf8"
98)
@@ -58,37 +57,6 @@ func normalizeUrlPaths(inputs []string) []string {
5857 return outputs
5958}
6059
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-
9260func normalizeFsPaths (inputs []string ) []string {
9361 outputs := make ([]string , 0 , len (inputs ))
9462
@@ -97,7 +65,7 @@ func normalizeFsPaths(inputs []string) []string {
9765 continue
9866 }
9967
100- abs , err := normalizeFsPath (input )
68+ abs , err := util . NormalizeFsPath (input )
10169 if err != nil {
10270 continue
10371 }
Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ func (h *handler) getResponseData(r *http.Request) (data *responseData) {
292292 rootRelPath = "./"
293293 }
294294
295- reqFsPath , _absErr := filepath . Abs (h .root + reqPath )
295+ reqFsPath , _absErr := util . NormalizeFsPath (h .root + reqPath )
296296 if _absErr != nil {
297297 reqFsPath = filepath .Clean (h .root + reqPath )
298298 }
Original file line number Diff line number Diff line change 1+ package util
2+
3+ import "unicode/utf8"
4+
5+ func AsciiToLowerCase (input string ) string {
6+ buffer := []byte (input )
7+ length := len (buffer )
8+
9+ for i := 0 ; i < length ; {
10+ r , w := utf8 .DecodeRune (buffer [i :])
11+ if w == 1 && r >= 'A' && r <= 'Z' {
12+ buffer [i ] += 'a' - 'A'
13+ }
14+
15+ i += w
16+ }
17+
18+ return string (buffer )
19+ }
Original file line number Diff line number Diff line change 1- package param
1+ package util
22
33import "testing"
44
55func TestAsciiToLowerCase (t * testing.T ) {
66 str := "Hello, 你好"
7- lower := asciiToLowerCase (str )
7+ lower := AsciiToLowerCase (str )
88 expect := "hello, 你好"
99 if lower != expect {
1010 t .Error (lower )
Original file line number Diff line number Diff line change @@ -42,3 +42,18 @@ func HasFsPrefixDir(fsPath, prefix string) bool {
4242
4343 return strings .HasPrefix (fsPath , prefix )
4444}
45+
46+ func NormalizeFsPath (input string ) (string , error ) {
47+ abs , err := filepath .Abs (input )
48+ if err != nil {
49+ return abs , err
50+ }
51+
52+ volume := filepath .VolumeName (abs )
53+ if len (volume ) > 0 {
54+ // suppose on windows platform, ignore ascii case in path name
55+ abs = AsciiToLowerCase (abs )
56+ }
57+
58+ return abs , err
59+ }
You can’t perform that action at this time.
0 commit comments