aboutsummaryrefslogtreecommitdiff
path: root/weed
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-08-15 10:03:56 -0700
committerchrislu <chris.lu@gmail.com>2022-08-15 10:03:56 -0700
commit9c588d4010af9f89a0a50b1efb454b8e3cd498a5 (patch)
tree1336174216eca5431165a1e9795de9df3ebc4bf4 /weed
parent96caf21d093d83922d5ba2726482af6e9b70f9a5 (diff)
parent55f90302a71662f6900b3bd9e00fbe108b724007 (diff)
downloadseaweedfs-9c588d4010af9f89a0a50b1efb454b8e3cd498a5.tar.xz
seaweedfs-9c588d4010af9f89a0a50b1efb454b8e3cd498a5.zip
Merge branch 'master' of https://github.com/seaweedfs/seaweedfs
Diffstat (limited to 'weed')
-rw-r--r--weed/s3api/s3api_object_handlers.go23
-rw-r--r--weed/s3api/s3api_object_handlers_test.go48
2 files changed, 70 insertions, 1 deletions
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go
index 75abd0e4d..f3b34fa4d 100644
--- a/weed/s3api/s3api_object_handlers.go
+++ b/weed/s3api/s3api_object_handlers.go
@@ -130,9 +130,30 @@ func urlPathEscape(object string) string {
return strings.Join(escapedParts, "/")
}
+func removeDuplicateSlashes(object string) string {
+ result := strings.Builder{}
+ result.Grow(len(object))
+
+ isLastSlash := false
+ for _, r := range object {
+ switch r {
+ case '/':
+ if !isLastSlash {
+ result.WriteRune(r)
+ }
+ isLastSlash = true
+ default:
+ result.WriteRune(r)
+ isLastSlash = false
+ }
+ }
+ return result.String()
+}
+
func (s3a *S3ApiServer) toFilerUrl(bucket, object string) string {
+ object = urlPathEscape(removeDuplicateSlashes(object))
destUrl := fmt.Sprintf("http://%s%s/%s%s",
- s3a.option.Filer.ToHttpAddress(), s3a.option.BucketsPath, bucket, urlPathEscape(object))
+ s3a.option.Filer.ToHttpAddress(), s3a.option.BucketsPath, bucket, object)
return destUrl
}
diff --git a/weed/s3api/s3api_object_handlers_test.go b/weed/s3api/s3api_object_handlers_test.go
new file mode 100644
index 000000000..d1043451d
--- /dev/null
+++ b/weed/s3api/s3api_object_handlers_test.go
@@ -0,0 +1,48 @@
+package s3api
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestRemoveDuplicateSlashes(t *testing.T) {
+ tests := []struct {
+ name string
+ path string
+ expectedResult string
+ }{
+ {
+ name: "empty",
+ path: "",
+ expectedResult: "",
+ },
+ {
+ name: "slash",
+ path: "/",
+ expectedResult: "/",
+ },
+ {
+ name: "object",
+ path: "object",
+ expectedResult: "object",
+ },
+ {
+ name: "correct path",
+ path: "/path/to/object",
+ expectedResult: "/path/to/object",
+ },
+ {
+ name: "path with duplicates",
+ path: "///path//to/object//",
+ expectedResult: "/path/to/object/",
+ },
+ }
+
+ for _, tst := range tests {
+ t.Run(tst.name, func(t *testing.T) {
+ obj := removeDuplicateSlashes(tst.path)
+ assert.Equal(t, tst.expectedResult, obj)
+ })
+ }
+}