forked from TrueCloudLab/rclone
fspath: improved detection of illegal remote names starting with dash (related to #4261)
This commit is contained in:
parent
8e6a469f98
commit
8b9f3bbe29
2 changed files with 4 additions and 9 deletions
|
@ -13,13 +13,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
configNameRe = `[\w\p{L}\p{N}.-]+(?: +[\w\p{L}\p{N}.-]+)*`
|
configNameRe = `[\w\p{L}\p{N}.]+(?:[ -]+[\w\p{L}\p{N}.-]+)*` // don't allow it to start with `-` as it complicates usage (#4261)
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errInvalidCharacters = errors.New("config name contains invalid characters - may only contain numbers, letters, `_`, `-`, `.` and space, while not start or end with space")
|
errInvalidCharacters = errors.New("config name contains invalid characters - may only contain numbers, letters, `_`, `-`, `.` and space, while not start with `-` or space, and not end with 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 `-`")
|
|
||||||
errBadConfigParam = errors.New("config parameters may only contain `0-9`, `A-Z`, `a-z` and `_`")
|
errBadConfigParam = errors.New("config parameters may only contain `0-9`, `A-Z`, `a-z` and `_`")
|
||||||
errEmptyConfigParam = errors.New("config parameters can't be empty")
|
errEmptyConfigParam = errors.New("config parameters can't be empty")
|
||||||
errConfigNameEmpty = errors.New("config name can't be empty")
|
errConfigNameEmpty = errors.New("config name can't be empty")
|
||||||
|
@ -42,10 +41,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ func TestCheckConfigName(t *testing.T) {
|
||||||
{"rem\\ote", errInvalidCharacters},
|
{"rem\\ote", errInvalidCharacters},
|
||||||
{"[remote", errInvalidCharacters},
|
{"[remote", errInvalidCharacters},
|
||||||
{"*", errInvalidCharacters},
|
{"*", errInvalidCharacters},
|
||||||
{"-remote", errCantStartWithDash},
|
{"-remote", errInvalidCharacters},
|
||||||
{"r-emote-", nil},
|
{"r-emote-", nil},
|
||||||
{"_rem_ote_", nil},
|
{"_rem_ote_", nil},
|
||||||
{".", nil},
|
{".", nil},
|
||||||
|
@ -62,7 +62,7 @@ func TestCheckRemoteName(t *testing.T) {
|
||||||
{".:", nil},
|
{".:", nil},
|
||||||
{"..:", nil},
|
{"..:", nil},
|
||||||
{".r.e.m.o.t.e.:", nil},
|
{".r.e.m.o.t.e.:", nil},
|
||||||
{"-r-emote-:", nil},
|
{"-r-emote-:", errInvalidCharacters},
|
||||||
{"rem ote:", nil},
|
{"rem ote:", nil},
|
||||||
{"blåbær:", nil},
|
{"blåbær:", nil},
|
||||||
{"chữ Quốc ngữ:", nil},
|
{"chữ Quốc ngữ:", nil},
|
||||||
|
|
Loading…
Add table
Reference in a new issue