Skip to content

Commit 72d2660

Browse files
committed
feat: prevent converting filename to lower case
To keep original file path case for output download filename, try using original path case speified or got from file system.
1 parent ce12111 commit 72d2660

File tree

7 files changed

+10
-29
lines changed

7 files changed

+10
-29
lines changed

src/param/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ eachInput:
115115
continue
116116
}
117117
urlPath = util.CleanUrlPath(urlPath)
118-
fsPath, err := util.NormalizeFsPath(fsPath)
118+
fsPath, err := filepath.Abs(fsPath)
119119
if err != nil {
120120
errs = append(errs, err)
121121
continue

src/param/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"mjpclab.dev/ghfs/src/serverError"
77
"mjpclab.dev/ghfs/src/util"
88
"os"
9+
"path/filepath"
910
)
1011

1112
type Param struct {
@@ -97,7 +98,7 @@ func (param *Param) normalize() (errs []error) {
9798
var err error
9899

99100
// root
100-
param.Root, err = util.NormalizeFsPath(param.Root)
101+
param.Root, err = filepath.Abs(param.Root)
101102
errs = serverError.AppendError(errs, err)
102103

103104
// alias
@@ -145,7 +146,7 @@ func (param *Param) normalize() (errs []error) {
145146
errs = append(errs, es...)
146147
}
147148

148-
param.RestrictAccessDirs, es = normalizeAllPathValues(param.RestrictAccessDirs, true, util.NormalizeFsPath, util.ExtractHostsFromUrls)
149+
param.RestrictAccessDirs, es = normalizeAllPathValues(param.RestrictAccessDirs, true, filepath.Abs, util.ExtractHostsFromUrls)
149150
if len(es) == 0 {
150151
dedupAllPathValues(param.RestrictAccessDirs)
151152
} else {
@@ -156,7 +157,7 @@ func (param *Param) normalize() (errs []error) {
156157
param.HeadersUrls, es = normalizeAllPathValues(param.HeadersUrls, false, util.NormalizeUrlPath, normalizeHeaders)
157158
errs = append(errs, es...)
158159

159-
param.HeadersDirs, es = normalizeAllPathValues(param.HeadersDirs, false, util.NormalizeFsPath, normalizeHeaders)
160+
param.HeadersDirs, es = normalizeAllPathValues(param.HeadersDirs, false, filepath.Abs, normalizeHeaders)
160161
errs = append(errs, es...)
161162

162163
// upload/mkdir/delete/archive/cors/auth urls/dirs

src/param/util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package param
22

33
import (
44
"mjpclab.dev/ghfs/src/util"
5+
"path/filepath"
56
"strings"
67
"unicode/utf8"
78
)
@@ -119,7 +120,7 @@ func NormalizeFsPaths(inputs []string) []string {
119120
continue
120121
}
121122

122-
abs, err := util.NormalizeFsPath(input)
123+
abs, err := filepath.Abs(input)
123124
if err != nil {
124125
continue
125126
}

src/serverHandler/responseData.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99
"path"
10+
"path/filepath"
1011
"strings"
1112
)
1213

@@ -301,7 +302,7 @@ func (h *aliasHandler) getResponseData(r *http.Request) (data *responseData, fsP
301302
tailSlash := rawReqPath[len(rawReqPath)-1] == '/'
302303

303304
reqPath := util.CleanUrlPath(rawReqPath[len(h.aliasPrefix):])
304-
reqFsPath, _ := util.NormalizeFsPath(h.root + reqPath)
305+
reqFsPath, _ := filepath.Abs(h.root + reqPath)
305306

306307
status := http.StatusOK
307308

src/util/path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func hasPrefixDirNoCase(absPath, prefix string, separator byte) bool {
9393
return false
9494
}
9595

96-
func NormalizeUrlPath(input string) (string, error) { // keep same func signature as `NormalizeFsPath`
96+
func NormalizeUrlPath(input string) (string, error) {
9797
result := CleanUrlPath(input)
9898
return result, nil
9999
}

src/util/path_unix.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33

44
package util
55

6-
import "path/filepath"
7-
86
var IsPathEqual = IsStrEqualAccurate
97

108
var HasUrlPrefixDir = HasUrlPrefixDirAccurate
119
var HasFsPrefixDir = HasFsPrefixDirAccurate
12-
13-
func NormalizeFsPath(input string) (string, error) {
14-
return filepath.Abs(input)
15-
}

src/util/path_windows.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,7 @@
33

44
package util
55

6-
import (
7-
"path/filepath"
8-
"strings"
9-
)
10-
116
var IsPathEqual = IsStrEqualNoCase
127

138
var HasUrlPrefixDir = HasUrlPrefixDirNoCase
149
var HasFsPrefixDir = HasFsPrefixDirNoCase
15-
16-
func NormalizeFsPath(input string) (string, error) {
17-
abs, err := filepath.Abs(input)
18-
if err != nil {
19-
return abs, err
20-
}
21-
22-
abs = strings.ToLower(abs)
23-
24-
return abs, err
25-
}

0 commit comments

Comments
 (0)