aboutsummaryrefslogtreecommitdiff
path: root/weed/s3api/s3_constants/header_test.go
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2025-12-14 11:18:23 -0800
committerGitHub <noreply@github.com>2025-12-14 11:18:23 -0800
commita77674ead3c5f1f9bd21a46f6f90019f178c6a70 (patch)
tree5e99297ace743826b6936d011c32ffa256d95635 /weed/s3api/s3_constants/header_test.go
parenteb860752e6c0a86131e39d648f0a64364408ab93 (diff)
downloadseaweedfs-a77674ead3c5f1f9bd21a46f6f90019f178c6a70.tar.xz
seaweedfs-a77674ead3c5f1f9bd21a46f6f90019f178c6a70.zip
fix: use path instead of filepath for S3 object paths on Windows (#7739)
fix: use path instead of filepath for S3 object paths on Windows (#7733)
Diffstat (limited to 'weed/s3api/s3_constants/header_test.go')
-rw-r--r--weed/s3api/s3_constants/header_test.go132
1 files changed, 132 insertions, 0 deletions
diff --git a/weed/s3api/s3_constants/header_test.go b/weed/s3api/s3_constants/header_test.go
new file mode 100644
index 000000000..b16cfc6a8
--- /dev/null
+++ b/weed/s3api/s3_constants/header_test.go
@@ -0,0 +1,132 @@
+package s3_constants
+
+import (
+ "testing"
+)
+
+func TestNormalizeObjectKey(t *testing.T) {
+ tests := []struct {
+ name string
+ input string
+ expected string
+ }{
+ {
+ name: "simple key",
+ input: "file.txt",
+ expected: "/file.txt",
+ },
+ {
+ name: "key with leading slash",
+ input: "/file.txt",
+ expected: "/file.txt",
+ },
+ {
+ name: "key with directory",
+ input: "folder/file.txt",
+ expected: "/folder/file.txt",
+ },
+ {
+ name: "key with leading slash and directory",
+ input: "/folder/file.txt",
+ expected: "/folder/file.txt",
+ },
+ {
+ name: "key with duplicate slashes",
+ input: "folder//subfolder///file.txt",
+ expected: "/folder/subfolder/file.txt",
+ },
+ {
+ name: "Windows backslash - simple",
+ input: "folder\\file.txt",
+ expected: "/folder/file.txt",
+ },
+ {
+ name: "Windows backslash - nested",
+ input: "folder\\subfolder\\file.txt",
+ expected: "/folder/subfolder/file.txt",
+ },
+ {
+ name: "Windows backslash - with leading slash",
+ input: "/folder\\subfolder\\file.txt",
+ expected: "/folder/subfolder/file.txt",
+ },
+ {
+ name: "mixed slashes",
+ input: "folder\\subfolder/another\\file.txt",
+ expected: "/folder/subfolder/another/file.txt",
+ },
+ {
+ name: "Windows full path style (edge case)",
+ input: "C:\\Users\\test\\file.txt",
+ expected: "/C:/Users/test/file.txt",
+ },
+ {
+ name: "empty string",
+ input: "",
+ expected: "/",
+ },
+ {
+ name: "just a slash",
+ input: "/",
+ expected: "/",
+ },
+ {
+ name: "just a backslash",
+ input: "\\",
+ expected: "/",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result := NormalizeObjectKey(tt.input)
+ if result != tt.expected {
+ t.Errorf("NormalizeObjectKey(%q) = %q, want %q", tt.input, result, tt.expected)
+ }
+ })
+ }
+}
+
+func TestRemoveDuplicateSlashes(t *testing.T) {
+ tests := []struct {
+ name string
+ input string
+ expected string
+ }{
+ {
+ name: "no duplicates",
+ input: "/folder/file.txt",
+ expected: "/folder/file.txt",
+ },
+ {
+ name: "double slash",
+ input: "/folder//file.txt",
+ expected: "/folder/file.txt",
+ },
+ {
+ name: "triple slash",
+ input: "/folder///file.txt",
+ expected: "/folder/file.txt",
+ },
+ {
+ name: "multiple duplicate locations",
+ input: "//folder//subfolder///file.txt",
+ expected: "/folder/subfolder/file.txt",
+ },
+ {
+ name: "empty string",
+ input: "",
+ expected: "",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result := removeDuplicateSlashes(tt.input)
+ if result != tt.expected {
+ t.Errorf("removeDuplicateSlashes(%q) = %q, want %q", tt.input, result, tt.expected)
+ }
+ })
+ }
+}
+