fspath: change remote name regex to not match when leading/trailing space

This commit is contained in:
albertony 2022-09-16 16:57:49 +02:00 committed by Nick Craig-Wood
parent 3937233e1e
commit 683178a1f4
2 changed files with 19 additions and 31 deletions

View file

@ -13,7 +13,7 @@ import (
) )
const ( const (
configNameRe = `[\w. -]+` configNameRe = `[\w.-]+(?: +[\w.-]+)*`
) )
var ( var (

View file

@ -38,9 +38,9 @@ func TestCheckConfigName(t *testing.T) {
{"..", nil}, {"..", nil},
{".r.e.m.o.t.e.", nil}, {".r.e.m.o.t.e.", nil},
{"rem ote", nil}, {"rem ote", nil},
{"remote ", nil}, {"remote ", errInvalidCharacters},
{" remote", nil}, {" remote", errInvalidCharacters},
{" remote ", nil}, {" remote ", errInvalidCharacters},
} { } {
got := CheckConfigName(test.in) got := CheckConfigName(test.in)
assert.Equal(t, test.want, got, test.in) assert.Equal(t, test.want, got, test.in)
@ -60,9 +60,9 @@ func TestCheckRemoteName(t *testing.T) {
{".r.e.m.o.t.e.:", nil}, {".r.e.m.o.t.e.:", nil},
{"-r-emote-:", nil}, {"-r-emote-:", nil},
{"rem ote:", nil}, {"rem ote:", nil},
{"remote :", nil}, {"remote :", errInvalidCharacters},
{" remote:", nil}, {" remote:", errInvalidCharacters},
{" remote :", nil}, {" remote :", errInvalidCharacters},
{"", errInvalidCharacters}, {"", errInvalidCharacters},
{"rem:ote", errInvalidCharacters}, {"rem:ote", errInvalidCharacters},
{"rem:ote:", errInvalidCharacters}, {"rem:ote:", errInvalidCharacters},
@ -226,26 +226,14 @@ func TestParse(t *testing.T) {
Path: "/path/to/file", Path: "/path/to/file",
}, },
}, { }, {
in: "remote :/path/to/file", in: "remote :/path/to/file",
wantParsed: Parsed{ wantErr: errInvalidCharacters,
ConfigString: "remote ",
Name: "remote ",
Path: "/path/to/file",
},
}, { }, {
in: " remote:/path/to/file", in: " remote:/path/to/file",
wantParsed: Parsed{ wantErr: errInvalidCharacters,
ConfigString: " remote",
Name: " remote",
Path: "/path/to/file",
},
}, { }, {
in: " remote :/path/to/file", in: " remote :/path/to/file",
wantParsed: Parsed{ wantErr: errInvalidCharacters,
ConfigString: " remote ",
Name: " remote ",
Path: "/path/to/file",
},
}, { }, {
in: "rem#ote:/path/to/file", in: "rem#ote:/path/to/file",
wantErr: errInvalidCharacters, wantErr: errInvalidCharacters,
@ -482,9 +470,9 @@ func TestSplitFs(t *testing.T) {
{"rem.ote:potato/sausage", "rem.ote:", "potato/sausage", nil}, {"rem.ote:potato/sausage", "rem.ote:", "potato/sausage", nil},
{"rem ote:", "rem ote:", "", nil}, {"rem ote:", "rem ote:", "", nil},
{"remote :", "remote :", "", nil}, {"remote :", "", "", errInvalidCharacters},
{" remote:", " remote:", "", nil}, {" remote:", "", "", errInvalidCharacters},
{" remote :", " remote :", "", nil}, {" remote :", "", "", errInvalidCharacters},
{".:", ".:", "", nil}, {".:", ".:", "", nil},
{"..:", "..:", "", nil}, {"..:", "..:", "", nil},
@ -539,9 +527,9 @@ func TestSplit(t *testing.T) {
{"rem.ote:potato/sausage", "rem.ote:potato/", "sausage", nil}, {"rem.ote:potato/sausage", "rem.ote:potato/", "sausage", nil},
{"rem ote:", "rem ote:", "", nil}, {"rem ote:", "rem ote:", "", nil},
{"remote :", "remote :", "", nil}, {"remote :", "", "", errInvalidCharacters},
{" remote:", " remote:", "", nil}, {" remote:", "", "", errInvalidCharacters},
{" remote :", " remote :", "", nil}, {" remote :", "", "", errInvalidCharacters},
{".:", ".:", "", nil}, {".:", ".:", "", nil},
{"..:", "..:", "", nil}, {"..:", "..:", "", nil},