Browse Source
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 (#7739)
fix: use path instead of filepath for S3 object paths on Windows (#7733)pull/4038/merge
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 202 additions and 9 deletions
-
6weed/s3api/filer_multipart.go
-
62weed/s3api/filer_multipart_test.go
-
3weed/s3api/s3_constants/header.go
-
132weed/s3api/s3_constants/header_test.go
-
8weed/s3api/s3api_object_handlers_put.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) |
|||
} |
|||
}) |
|||
} |
|||
} |
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue