config: check config names more carefully and report errors - fixes #3506

Before this change it was possible to make a remote with an invalid
name in the config file, either manually or with `rclone config
create` (but not with `rclone config`).

When this remote was used, because it was invalid, rclone would
presume this remote name was a local directory for a very suprising
user experience!

This change checks remote names more carefully and returns errors
- when the user tries to use an invalid remote name on the command line
- when an invalid remote name is used in `rclone config create/update/password`
- when the user tries to enter an invalid remote name in `rclone config`

This does not prevent the user entering a remote name with invalid
characters in the config manually, but such a remote will fail
immediately when it is used on the command line.
This commit is contained in:
Nick Craig-Wood
2019-09-05 11:01:04 +01:00
parent 27a730ef8f
commit f1347139fa
6 changed files with 177 additions and 44 deletions

View File

@@ -1087,7 +1087,10 @@ func MustFind(name string) *RegInfo {
// ParseRemote deconstructs a path into configName, fsPath, looking up
// the fsName in the config file (returning NotFoundInConfigFile if not found)
func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, err error) {
configName, fsPath = fspath.Parse(path)
configName, fsPath, err = fspath.Parse(path)
if err != nil {
return nil, "", "", err
}
var fsName string
var ok bool
if configName != "" {