aboutsummaryrefslogtreecommitdiff
path: root/weed/util
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2025-12-05 17:40:32 -0800
committerGitHub <noreply@github.com>2025-12-05 17:40:32 -0800
commit28ac536280a2d4920da9211a0d450c64f0ed19be (patch)
tree1770ed603b1f4a598d259f5d3d81d8e2495f1fad /weed/util
parent89b6deaefa6e5f5f297237e9dfa82eb50c897349 (diff)
downloadseaweedfs-28ac536280a2d4920da9211a0d450c64f0ed19be.tar.xz
seaweedfs-28ac536280a2d4920da9211a0d450c64f0ed19be.zip
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
Diffstat (limited to 'weed/util')
-rw-r--r--weed/util/fullpath.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/weed/util/fullpath.go b/weed/util/fullpath.go
index c145919da..b485cae0d 100644
--- a/weed/util/fullpath.go
+++ b/weed/util/fullpath.go
@@ -1,6 +1,7 @@
package util
import (
+ "path"
"path/filepath"
"strings"
)
@@ -85,3 +86,15 @@ func StringSplit(separatedValues string, sep string) []string {
}
return strings.Split(separatedValues, sep)
}
+
+// CleanWindowsPath normalizes Windows-style backslashes to forward slashes.
+// This handles paths from Windows clients where paths use backslashes.
+func CleanWindowsPath(p string) string {
+ return strings.ReplaceAll(p, "\\", "/")
+}
+
+// CleanWindowsPathBase normalizes Windows-style backslashes to forward slashes
+// and returns the base name of the path.
+func CleanWindowsPathBase(p string) string {
+ return path.Base(strings.ReplaceAll(p, "\\", "/"))
+}