lib/bucket: fix tidying of // in object keys #5858

Before this change, bucket.Join would tidy up object keys by removing
repeated / in them. This means we can't access objects with // in them
which is valid for object keys (but not for file system paths).

This could have consequences for users who are relying on rclone to
fix improper paths for them.
This commit is contained in:
Nick Craig-Wood 2025-01-02 15:59:56 +00:00
parent b4990cd858
commit fe19184084
2 changed files with 7 additions and 5 deletions

View File

@ -31,7 +31,9 @@ func Split(absPath string) (bucket, bucketPath string) {
// Join path1 and path2
//
// Like path.Join but does not clean the path - useful to preserve trailing /
// Like path.Join but does not clean the path - useful to preserve trailing /.
//
// It also does not clean multiple // in the path.
func Join(path1, path2 string) string {
if path1 == "" {
return path2
@ -39,7 +41,7 @@ func Join(path1, path2 string) string {
if path2 == "" {
return path1
}
return strings.TrimSuffix(path1, "/") + "/" + strings.TrimPrefix(path2, "/")
return path1 + "/" + path2
}
// IsAllSlashes returns true if s is all / characters.

View File

@ -34,10 +34,10 @@ func TestJoin(t *testing.T) {
{in1: "in1", in2: "", want: "in1"},
{in1: "", in2: "in2", want: "in2"},
{in1: "in1", in2: "in2", want: "in1/in2"},
{in1: "in1/", in2: "in2", want: "in1/in2"},
{in1: "in1", in2: "/in2", want: "in1/in2"},
{in1: "in1/", in2: "in2", want: "in1//in2"},
{in1: "in1", in2: "/in2", want: "in1//in2"},
{in1: "in1", in2: "in2/", want: "in1/in2/"},
{in1: "/in1", in2: "/in2", want: "/in1/in2"},
{in1: "/in1", in2: "/in2", want: "/in1//in2"},
{in1: "/in1", in2: "../in2", want: "/in1/../in2"},
} {
got := Join(test.in1, test.in2)