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
3
3
import (
4
4
"../goNixArgParser"
5
5
"../serverErrHandler"
6
+ "../util"
6
7
"errors"
7
8
"fmt"
8
9
"io/ioutil"
@@ -193,7 +194,7 @@ func doParseCli() []*Param {
193
194
194
195
// root
195
196
root , _ := result .GetString ("root" )
196
- root , _ = normalizeFsPath (root )
197
+ root , _ = util . NormalizeFsPath (root )
197
198
param .Root = root
198
199
199
200
// certificate
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package param
3
3
import (
4
4
"../util"
5
5
"path"
6
- "path/filepath"
7
6
"strings"
8
7
"unicode/utf8"
9
8
)
@@ -58,37 +57,6 @@ func normalizeUrlPaths(inputs []string) []string {
58
57
return outputs
59
58
}
60
59
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
-
92
60
func normalizeFsPaths (inputs []string ) []string {
93
61
outputs := make ([]string , 0 , len (inputs ))
94
62
@@ -97,7 +65,7 @@ func normalizeFsPaths(inputs []string) []string {
97
65
continue
98
66
}
99
67
100
- abs , err := normalizeFsPath (input )
68
+ abs , err := util . NormalizeFsPath (input )
101
69
if err != nil {
102
70
continue
103
71
}
Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ func (h *handler) getResponseData(r *http.Request) (data *responseData) {
292
292
rootRelPath = "./"
293
293
}
294
294
295
- reqFsPath , _absErr := filepath . Abs (h .root + reqPath )
295
+ reqFsPath , _absErr := util . NormalizeFsPath (h .root + reqPath )
296
296
if _absErr != nil {
297
297
reqFsPath = filepath .Clean (h .root + reqPath )
298
298
}
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
2
2
3
3
import "testing"
4
4
5
5
func TestAsciiToLowerCase (t * testing.T ) {
6
6
str := "Hello, 你好"
7
- lower := asciiToLowerCase (str )
7
+ lower := AsciiToLowerCase (str )
8
8
expect := "hello, 你好"
9
9
if lower != expect {
10
10
t .Error (lower )
Original file line number Diff line number Diff line change @@ -42,3 +42,18 @@ func HasFsPrefixDir(fsPath, prefix string) bool {
42
42
43
43
return strings .HasPrefix (fsPath , prefix )
44
44
}
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