Remove duplicate slashes in object path to prevent 500 errors (#3442)
This commit is contained in:
48
weed/s3api/s3api_object_handlers_test.go
Normal file
48
weed/s3api/s3api_object_handlers_test.go
Normal file
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user