mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 08:23:47 +01:00
fspath: Stop empty strings being a valid path - fixes #4239
Before this change you could use "" as a valid remote, so `rclone lsf ""` would work. This was treated as the current directory. This is unexpected and creates a footgun for scripting when an empty variable is passed to rclone by accident. This fix returns the error "can't use empty string as a path" instead of allowing it.
This commit is contained in:
parent
ecdfd80459
commit
eb6e9b194a
@ -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]) {
|
||||
|
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user