"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
dropbox: decode received shared-file names - fixes #9707
Sanjay Kanth Af3a7aaf635cc
diff --git a/backend/dropbox/dropbox.go b/backend/dropbox/dropbox.goindex b43f0876c..9d41a81c6 100644--- a/backend/dropbox/dropbox.go+++ b/backend/dropbox/dropbox.go@@ -1010,7 +1010,7 @@ func (f *Fs) listReceivedFiles(ctx context.Context, callback func(fs.DirEntry) e}}for _, entry := range res.Entries {- entryPath := entry.Name+ entryPath := f.opt.Enc.ToStandardName(entry.Name)o := &Object{fs: f,url: entry.PreviewUrl,diff --git a/backend/dropbox/dropbox_internal_test.go b/backend/dropbox/dropbox_internal_test.goindex fe2f46fa1..c25f6124a 100644--- a/backend/dropbox/dropbox_internal_test.go+++ b/backend/dropbox/dropbox_internal_test.go@@ -2,7 +2,9 @@ package dropboximport ("context"+ "encoding/json""errors"+ "fmt""io""net/http""net/http/httptest"@@ -12,9 +14,11 @@ import ("github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox""github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"+ "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/sharing""github.com/rclone/rclone/fs""github.com/rclone/rclone/fstest/fstests""github.com/rclone/rclone/lib/batcher"+ "github.com/rclone/rclone/lib/encoder""github.com/rclone/rclone/lib/pacer""github.com/stretchr/testify/assert""github.com/stretchr/testify/require"@@ -318,3 +322,91 @@ func (f *Fs) InternalTest(t *testing.T) {}var _ fstests.InternalTester = (*Fs)(nil)++// newSharingTestFs builds a minimal *Fs whose sharing client talks to a+// local mock server instead of the real Dropbox API.+func newSharingTestFs(t *testing.T, handler http.HandlerFunc) *Fs {+ t.Helper()+ ts := httptest.NewServer(handler)+ t.Cleanup(ts.Close)++ cfg := dropbox.Config{+ Client: &http.Client{Transport: http.DefaultTransport},+ URLGenerator: func(hostType, namespace, route string) string {+ return fmt.Sprintf("%s/2/%s/%s", ts.URL, namespace, route)+ },+ }++ return &Fs{+ opt: Options{+ Enc: encoder.Base |+ encoder.EncodeBackSlash |+ encoder.EncodeDel |+ encoder.EncodeRightSpace |+ encoder.EncodeInvalidUtf8,+ },+ sharing: sharing.NewContext(cfg),+ pacer: fs.NewPacer(context.Background(), pacer.NewDefault(pacer.MinSleep(time.Millisecond))),+ }+}++func mustParseDBXTime(t *testing.T, s string) *dropbox.DBXTime {+ t.Helper()+ tm, err := time.Parse(time.RFC3339, s)+ require.NoError(t, err)+ return (*dropbox.DBXTime)(&tm)+}++func receivedFilesHandler(t *testing.T, rawName string) http.HandlerFunc {+ return func(w http.ResponseWriter, r *http.Request) {+ if !strings.Contains(r.URL.Path, "list_received_files") {+ http.NotFound(w, r)+ return+ }+ resp := sharing.ListFilesResult{+ Entries: []*sharing.SharedFileMetadata{{+ Id: "id:123",+ Name: rawName,+ PreviewUrl: "https://dropbox.com/preview/123",+ Policy: &sharing.FolderPolicy{},+ TimeInvited: mustParseDBXTime(t, "2024-01-01T00:00:00Z"),+ }},+ }+ w.Header().Set("Content-Type", "application/json")+ _ = json.NewEncoder(w).Encode(resp)+ }+}++// TestListReceivedFilesDecodesName confirms received-file names are decoded+// via Enc.ToStandardName before being returned, matching listSharedFolders'+// handling of shared-folder names.+func TestListReceivedFilesDecodesName(t *testing.T) {+ const rawName = "report.txt␠"+ f := newSharingTestFs(t, receivedFilesHandler(t, rawName))++ wantName := f.opt.Enc.ToStandardName(rawName)+ require.NotEqual(t, rawName, wantName)++ var gotNames []string+ err := f.listReceivedFiles(context.Background(), func(entry fs.DirEntry) error {+ gotNames = append(gotNames, entry.Remote())+ return nil+ })+ require.NoError(t, err)+ require.Len(t, gotNames, 1)+ assert.Equal(t, wantName, gotNames[0])+}++// TestFindSharedFileResolvesDecodedName confirms findSharedFile can look up+// a received file by its standard, decoded rclone-visible name.+func TestFindSharedFileResolvesDecodedName(t *testing.T) {+ const rawName = "report.txt␠"+ f := newSharingTestFs(t, receivedFilesHandler(t, rawName))++ encodedName := f.opt.Enc.ToStandardName(rawName)+ require.NotEqual(t, rawName, encodedName)++ o, err := f.findSharedFile(context.Background(), encodedName)+ require.NoError(t, err)+ assert.Equal(t, encodedName, o.remote)+}