config: reject remote names starting with a dash. (#4261)
This commit is contained in:
parent
62650a3eb3
commit
2d88d24881
2 changed files with 8 additions and 0 deletions
|
@ -19,6 +19,7 @@ const (
|
||||||
var (
|
var (
|
||||||
errInvalidCharacters = errors.New("config name contains invalid characters - may only contain 0-9, A-Z ,a-z ,_ , - and space ")
|
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")
|
errCantBeEmpty = errors.New("can't use empty string as a path")
|
||||||
|
errCantStartWithDash = errors.New("config name starts with -")
|
||||||
|
|
||||||
// urlMatcher is a pattern to match an rclone URL
|
// urlMatcher is a pattern to match an rclone URL
|
||||||
// note that this matches invalid remoteNames
|
// note that this matches invalid remoteNames
|
||||||
|
@ -36,6 +37,10 @@ func CheckConfigName(configName string) error {
|
||||||
if !configNameMatcher.MatchString(configName) {
|
if !configNameMatcher.MatchString(configName) {
|
||||||
return errInvalidCharacters
|
return errInvalidCharacters
|
||||||
}
|
}
|
||||||
|
// Reject configName, if it starts with -, complicates usage. (#4261)
|
||||||
|
if strings.HasPrefix(configName, "-") {
|
||||||
|
return errCantStartWithDash
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ func TestCheckConfigName(t *testing.T) {
|
||||||
{"rem\\ote", errInvalidCharacters},
|
{"rem\\ote", errInvalidCharacters},
|
||||||
{"[remote", errInvalidCharacters},
|
{"[remote", errInvalidCharacters},
|
||||||
{"*", errInvalidCharacters},
|
{"*", errInvalidCharacters},
|
||||||
|
{"-remote", errCantStartWithDash},
|
||||||
|
{"r-emote-", nil},
|
||||||
|
{"_rem_ote_", nil},
|
||||||
} {
|
} {
|
||||||
got := CheckConfigName(test.in)
|
got := CheckConfigName(test.in)
|
||||||
assert.Equal(t, test.want, got, test.in)
|
assert.Equal(t, test.want, got, test.in)
|
||||||
|
|
Loading…
Reference in a new issue