config: allow dot in remote names (#5606)

This commit is contained in:
albertony 2021-11-01 20:50:06 +01:00 committed by GitHub
parent b3217adf08
commit 39e2af7974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 6 deletions

View File

@ -332,7 +332,7 @@ Will get their own names
### Valid remote names
Remote names are case sensitive, and must adhere to the following rules:
- May only contain `0`-`9`, `A`-`Z`, `a`-`z`, `_`, `-` and space.
- May only contain `0`-`9`, `A`-`Z`, `a`-`z`, `_`, `-`, `.` and space.
- May not start with `-` or space.
Quoting and the shell

View File

@ -13,12 +13,12 @@ import (
)
const (
configNameRe = `[\w_ -]+`
configNameRe = `[\w_. -]+`
remoteNameRe = `^(:?` + configNameRe + `)`
)
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")
errCantStartWithDash = errors.New("config name starts with `-`")
errBadConfigParam = errors.New("config parameters may only contain `0-9`, `A-Z`, `a-z` and `_`")

View File

@ -35,6 +35,9 @@ func TestCheckConfigName(t *testing.T) {
{"-remote", errCantStartWithDash},
{"r-emote-", nil},
{"_rem_ote_", nil},
{".", nil},
{"..", nil},
{".r.e.m.o.t.e.", nil},
} {
got := CheckConfigName(test.in)
assert.Equal(t, test.want, got, test.in)
@ -49,6 +52,9 @@ func TestCheckRemoteName(t *testing.T) {
{":remote:", nil},
{":s3:", nil},
{"remote:", nil},
{".:", nil},
{"..:", nil},
{".r.e.m.o.t.e.:", nil},
{"", errInvalidCharacters},
{"rem:ote", errInvalidCharacters},
{"rem:ote:", errInvalidCharacters},
@ -159,6 +165,27 @@ func TestParse(t *testing.T) {
ConfigString: "",
Path: "path/to/file",
},
}, {
in: ".:",
wantParsed: Parsed{
ConfigString: ".",
Name: ".",
Path: "",
},
}, {
in: "..:",
wantParsed: Parsed{
ConfigString: "..",
Name: "..",
Path: "",
},
}, {
in: ".:colon.txt",
wantParsed: Parsed{
ConfigString: ".",
Name: ".",
Path: "colon.txt",
},
}, {
in: "remote:path/to/file",
wantParsed: Parsed{
@ -177,7 +204,14 @@ func TestParse(t *testing.T) {
Path: "/path/to/file",
},
}, {
in: "rem.ote:/path/to/file",
in: "rem.ote:/path/to/file",
wantParsed: Parsed{
ConfigString: "rem.ote",
Name: "rem.ote",
Path: "/path/to/file",
},
}, {
in: "rem#ote:/path/to/file",
wantErr: errInvalidCharacters,
}, {
in: ":backend:/path/to/file",
@ -186,6 +220,13 @@ func TestParse(t *testing.T) {
Name: ":backend",
Path: "/path/to/file",
},
}, {
in: ":back.end:/path/to/file",
wantParsed: Parsed{
ConfigString: ":back.end",
Name: ":back.end",
Path: "/path/to/file",
},
}, {
in: ":bac*kend:/path/to/file",
wantErr: errInvalidCharacters,
@ -218,6 +259,20 @@ func TestParse(t *testing.T) {
Path: `\path\to\file`,
},
noWin: true,
}, {
in: `.`,
wantParsed: Parsed{
Name: "",
Path: `.`,
},
noWin: true,
}, {
in: `..`,
wantParsed: Parsed{
Name: "",
Path: `..`,
},
noWin: true,
}, {
in: `remote:\path\to\file`,
wantParsed: Parsed{
@ -388,7 +443,12 @@ func TestSplitFs(t *testing.T) {
{"remote:/potato", "remote:", "/potato", nil},
{"remote:/potato/potato", "remote:", "/potato/potato", nil},
{"remote:potato/sausage", "remote:", "potato/sausage", nil},
{"rem.ote:potato/sausage", "", "", errInvalidCharacters},
{"rem.ote:potato/sausage", "rem.ote:", "potato/sausage", nil},
{".:", ".:", "", nil},
{"..:", "..:", "", nil},
{".:potato/sausage", ".:", "potato/sausage", nil},
{"..:potato/sausage", "..:", "potato/sausage", nil},
{":remote:", ":remote:", "", nil},
{":remote:potato", ":remote:", "potato", nil},
@ -396,8 +456,14 @@ func TestSplitFs(t *testing.T) {
{":remote:/potato", ":remote:", "/potato", nil},
{":remote:/potato/potato", ":remote:", "/potato/potato", nil},
{":remote:potato/sausage", ":remote:", "potato/sausage", nil},
{":rem.ote:potato/sausage", ":rem.ote:", "potato/sausage", nil},
{":rem[ote:potato/sausage", "", "", errInvalidCharacters},
{":.:", ":.:", "", nil},
{":..:", ":..:", "", nil},
{":.:potato/sausage", ":.:", "potato/sausage", nil},
{":..:potato/sausage", ":..:", "potato/sausage", nil},
{"/", "", "/", nil},
{"/root", "", "/root", nil},
{"/a/b", "", "/a/b", nil},
@ -429,7 +495,12 @@ func TestSplit(t *testing.T) {
{"remote:/potato", "remote:/", "potato", nil},
{"remote:/potato/potato", "remote:/potato/", "potato", nil},
{"remote:potato/sausage", "remote:potato/", "sausage", nil},
{"rem.ote:potato/sausage", "", "", errInvalidCharacters},
{"rem.ote:potato/sausage", "rem.ote:potato/", "sausage", nil},
{".:", ".:", "", nil},
{"..:", "..:", "", nil},
{".:potato/sausage", ".:potato/", "sausage", nil},
{"..:potato/sausage", "..:potato/", "sausage", nil},
{":remote:", ":remote:", "", nil},
{":remote:potato", ":remote:", "potato", nil},
@ -437,8 +508,14 @@ func TestSplit(t *testing.T) {
{":remote:/potato", ":remote:/", "potato", nil},
{":remote:/potato/potato", ":remote:/potato/", "potato", nil},
{":remote:potato/sausage", ":remote:potato/", "sausage", nil},
{":rem.ote:potato/sausage", ":rem.ote:potato/", "sausage", nil},
{":rem[ote:potato/sausage", "", "", errInvalidCharacters},
{":.:", ":.:", "", nil},
{":..:", ":..:", "", nil},
{":.:potato/sausage", ":.:potato/", "sausage", nil},
{":..:potato/sausage", ":..:potato/", "sausage", nil},
{"/", "/", "", nil},
{"/root", "/", "root", nil},
{"/a/b", "/a/", "b", nil},