config: allow dot in remote names (#5606)
This commit is contained in:
parent
b3217adf08
commit
39e2af7974
3 changed files with 83 additions and 6 deletions
|
@ -332,7 +332,7 @@ Will get their own names
|
||||||
### Valid remote names
|
### Valid remote names
|
||||||
|
|
||||||
Remote names are case sensitive, and must adhere to the following rules:
|
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.
|
- May not start with `-` or space.
|
||||||
|
|
||||||
Quoting and the shell
|
Quoting and the shell
|
||||||
|
|
|
@ -13,12 +13,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
configNameRe = `[\w_ -]+`
|
configNameRe = `[\w_. -]+`
|
||||||
remoteNameRe = `^(:?` + configNameRe + `)`
|
remoteNameRe = `^(:?` + configNameRe + `)`
|
||||||
)
|
)
|
||||||
|
|
||||||
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 `-`")
|
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 `_`")
|
||||||
|
|
|
@ -35,6 +35,9 @@ func TestCheckConfigName(t *testing.T) {
|
||||||
{"-remote", errCantStartWithDash},
|
{"-remote", errCantStartWithDash},
|
||||||
{"r-emote-", nil},
|
{"r-emote-", nil},
|
||||||
{"_rem_ote_", nil},
|
{"_rem_ote_", nil},
|
||||||
|
{".", nil},
|
||||||
|
{"..", nil},
|
||||||
|
{".r.e.m.o.t.e.", 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)
|
||||||
|
@ -49,6 +52,9 @@ func TestCheckRemoteName(t *testing.T) {
|
||||||
{":remote:", nil},
|
{":remote:", nil},
|
||||||
{":s3:", nil},
|
{":s3:", nil},
|
||||||
{"remote:", nil},
|
{"remote:", nil},
|
||||||
|
{".:", nil},
|
||||||
|
{"..:", nil},
|
||||||
|
{".r.e.m.o.t.e.:", nil},
|
||||||
{"", errInvalidCharacters},
|
{"", errInvalidCharacters},
|
||||||
{"rem:ote", errInvalidCharacters},
|
{"rem:ote", errInvalidCharacters},
|
||||||
{"rem:ote:", errInvalidCharacters},
|
{"rem:ote:", errInvalidCharacters},
|
||||||
|
@ -159,6 +165,27 @@ func TestParse(t *testing.T) {
|
||||||
ConfigString: "",
|
ConfigString: "",
|
||||||
Path: "path/to/file",
|
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",
|
in: "remote:path/to/file",
|
||||||
wantParsed: Parsed{
|
wantParsed: Parsed{
|
||||||
|
@ -177,7 +204,14 @@ func TestParse(t *testing.T) {
|
||||||
Path: "/path/to/file",
|
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,
|
wantErr: errInvalidCharacters,
|
||||||
}, {
|
}, {
|
||||||
in: ":backend:/path/to/file",
|
in: ":backend:/path/to/file",
|
||||||
|
@ -186,6 +220,13 @@ func TestParse(t *testing.T) {
|
||||||
Name: ":backend",
|
Name: ":backend",
|
||||||
Path: "/path/to/file",
|
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",
|
in: ":bac*kend:/path/to/file",
|
||||||
wantErr: errInvalidCharacters,
|
wantErr: errInvalidCharacters,
|
||||||
|
@ -218,6 +259,20 @@ func TestParse(t *testing.T) {
|
||||||
Path: `\path\to\file`,
|
Path: `\path\to\file`,
|
||||||
},
|
},
|
||||||
noWin: true,
|
noWin: true,
|
||||||
|
}, {
|
||||||
|
in: `.`,
|
||||||
|
wantParsed: Parsed{
|
||||||
|
Name: "",
|
||||||
|
Path: `.`,
|
||||||
|
},
|
||||||
|
noWin: true,
|
||||||
|
}, {
|
||||||
|
in: `..`,
|
||||||
|
wantParsed: Parsed{
|
||||||
|
Name: "",
|
||||||
|
Path: `..`,
|
||||||
|
},
|
||||||
|
noWin: true,
|
||||||
}, {
|
}, {
|
||||||
in: `remote:\path\to\file`,
|
in: `remote:\path\to\file`,
|
||||||
wantParsed: Parsed{
|
wantParsed: Parsed{
|
||||||
|
@ -388,7 +443,12 @@ func TestSplitFs(t *testing.T) {
|
||||||
{"remote:/potato", "remote:", "/potato", nil},
|
{"remote:/potato", "remote:", "/potato", nil},
|
||||||
{"remote:/potato/potato", "remote:", "/potato/potato", nil},
|
{"remote:/potato/potato", "remote:", "/potato/potato", nil},
|
||||||
{"remote:potato/sausage", "remote:", "potato/sausage", 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:", ":remote:", "", nil},
|
||||||
{":remote:potato", ":remote:", "potato", nil},
|
{":remote:potato", ":remote:", "potato", nil},
|
||||||
|
@ -396,8 +456,14 @@ func TestSplitFs(t *testing.T) {
|
||||||
{":remote:/potato", ":remote:", "/potato", nil},
|
{":remote:/potato", ":remote:", "/potato", nil},
|
||||||
{":remote:/potato/potato", ":remote:", "/potato/potato", nil},
|
{":remote:/potato/potato", ":remote:", "/potato/potato", nil},
|
||||||
{":remote:potato/sausage", ":remote:", "potato/sausage", nil},
|
{":remote:potato/sausage", ":remote:", "potato/sausage", nil},
|
||||||
|
{":rem.ote:potato/sausage", ":rem.ote:", "potato/sausage", nil},
|
||||||
{":rem[ote:potato/sausage", "", "", errInvalidCharacters},
|
{":rem[ote:potato/sausage", "", "", errInvalidCharacters},
|
||||||
|
|
||||||
|
{":.:", ":.:", "", nil},
|
||||||
|
{":..:", ":..:", "", nil},
|
||||||
|
{":.:potato/sausage", ":.:", "potato/sausage", nil},
|
||||||
|
{":..:potato/sausage", ":..:", "potato/sausage", nil},
|
||||||
|
|
||||||
{"/", "", "/", nil},
|
{"/", "", "/", nil},
|
||||||
{"/root", "", "/root", nil},
|
{"/root", "", "/root", nil},
|
||||||
{"/a/b", "", "/a/b", nil},
|
{"/a/b", "", "/a/b", nil},
|
||||||
|
@ -429,7 +495,12 @@ func TestSplit(t *testing.T) {
|
||||||
{"remote:/potato", "remote:/", "potato", nil},
|
{"remote:/potato", "remote:/", "potato", nil},
|
||||||
{"remote:/potato/potato", "remote:/potato/", "potato", nil},
|
{"remote:/potato/potato", "remote:/potato/", "potato", nil},
|
||||||
{"remote:potato/sausage", "remote:potato/", "sausage", 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:", ":remote:", "", nil},
|
||||||
{":remote:potato", ":remote:", "potato", nil},
|
{":remote:potato", ":remote:", "potato", nil},
|
||||||
|
@ -437,8 +508,14 @@ func TestSplit(t *testing.T) {
|
||||||
{":remote:/potato", ":remote:/", "potato", nil},
|
{":remote:/potato", ":remote:/", "potato", nil},
|
||||||
{":remote:/potato/potato", ":remote:/potato/", "potato", nil},
|
{":remote:/potato/potato", ":remote:/potato/", "potato", nil},
|
||||||
{":remote:potato/sausage", ":remote:potato/", "sausage", nil},
|
{":remote:potato/sausage", ":remote:potato/", "sausage", nil},
|
||||||
|
{":rem.ote:potato/sausage", ":rem.ote:potato/", "sausage", nil},
|
||||||
{":rem[ote:potato/sausage", "", "", errInvalidCharacters},
|
{":rem[ote:potato/sausage", "", "", errInvalidCharacters},
|
||||||
|
|
||||||
|
{":.:", ":.:", "", nil},
|
||||||
|
{":..:", ":..:", "", nil},
|
||||||
|
{":.:potato/sausage", ":.:potato/", "sausage", nil},
|
||||||
|
{":..:potato/sausage", ":..:potato/", "sausage", nil},
|
||||||
|
|
||||||
{"/", "/", "", nil},
|
{"/", "/", "", nil},
|
||||||
{"/root", "/", "root", nil},
|
{"/root", "/", "root", nil},
|
||||||
{"/a/b", "/a/", "b", nil},
|
{"/a/b", "/a/", "b", nil},
|
||||||
|
|
Loading…
Add table
Reference in a new issue