Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fspath: Stop empty strings being a valid path - fixes #4239

Nick Craig-Woodeb6e9b194a33
diff --git a/fs/fspath/path.go b/fs/fspath/path.go
index d0684f941..fd6034181 100644
--- a/fs/fspath/path.go
+++ b/fs/fspath/path.go
@@ -18,6 +18,7 @@ const (
var (
errInvalidCharacters = errors.New("config name contains invalid characters - may only contain 0-9, A-Z ,a-z ,_ , - and space ")
+ errCantBeEmpty = errors.New("can't use empty string as a path")
// urlMatcher is a pattern to match an rclone URL
// note that this matches invalid remoteNames
@@ -55,8 +56,12 @@ func CheckRemoteName(remoteName string) error {
//
// Note that this will turn \ into / in the fsPath on Windows
//
-// An error may be returned if the remote name has invalid characters in it.
+// An error may be returned if the remote name has invalid characters
+// in it or if the path is empty.
func Parse(path string) (configName, fsPath string, err error) {
+ if path == "" {
+ return "", "", errCantBeEmpty
+ }
parts := urlMatcher.FindStringSubmatch(path)
configName, fsPath = "", path
if parts != nil && !driveletter.IsDriveLetter(parts[1]) {
diff --git a/fs/fspath/path_test.go b/fs/fspath/path_test.go
index 5b85df215..5e8cba2e5 100644
--- a/fs/fspath/path_test.go
+++ b/fs/fspath/path_test.go
@@ -55,7 +55,7 @@ func TestParse(t *testing.T) {
in, wantConfigName, wantFsPath string
wantErr error
}{
- {"", "", "", nil},
+ {"", "", "", errCantBeEmpty},
{":", "", "", errInvalidCharacters},
{"::", ":", "", errInvalidCharacters},
{":/:", "", "/:", errInvalidCharacters},
@@ -91,7 +91,7 @@ func TestSplit(t *testing.T) {
remote, wantParent, wantLeaf string
wantErr error
}{
- {"", "", "", nil},
+ {"", "", "", errCantBeEmpty},
{"remote:", "remote:", "", nil},
{"remote:potato", "remote:", "potato", nil},