fix: normalize Windows backslash paths in weed admin file uploads (#7636)
fix: normalize Windows backslash paths in file uploads When uploading files from a Windows client to a Linux server, file paths containing backslashes were not being properly interpreted as directory separators. This caused files intended for subdirectories to be created in the root directory with backslashes in their filenames. Changes: - Add util.CleanWindowsPath and util.CleanWindowsPathBase helper functions in weed/util/fullpath.go for reusable path normalization - Use path.Join/path.Clean/path.Base instead of filepath equivalents for URL path semantics (filepath is OS-specific) - Apply normalization in weed admin handlers and filer upload parsing Fixes #7628
This commit is contained in:
@@ -128,7 +128,7 @@ func parseUpload(r *http.Request, sizeLimit int64, pu *ParsedUpload) (e error) {
|
||||
|
||||
pu.FileName = part.FileName()
|
||||
if pu.FileName != "" {
|
||||
pu.FileName = path.Base(pu.FileName)
|
||||
pu.FileName = util.CleanWindowsPathBase(pu.FileName)
|
||||
}
|
||||
|
||||
dataSize, e = pu.bytesBuffer.ReadFrom(io.LimitReader(part, sizeLimit+1))
|
||||
@@ -169,7 +169,7 @@ func parseUpload(r *http.Request, sizeLimit int64, pu *ParsedUpload) (e error) {
|
||||
|
||||
// update
|
||||
pu.Data = pu.bytesBuffer.Bytes()
|
||||
pu.FileName = path.Base(fName)
|
||||
pu.FileName = util.CleanWindowsPathBase(fName)
|
||||
contentType = part.Header.Get("Content-Type")
|
||||
part = part2
|
||||
break
|
||||
@@ -207,7 +207,7 @@ func parseUpload(r *http.Request, sizeLimit int64, pu *ParsedUpload) (e error) {
|
||||
}
|
||||
|
||||
if pu.FileName != "" {
|
||||
pu.FileName = path.Base(pu.FileName)
|
||||
pu.FileName = util.CleanWindowsPathBase(pu.FileName)
|
||||
} else {
|
||||
pu.FileName = path.Base(r.URL.Path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user