From 683178a1f4d205a56c8a96593cf77ba6ef149474 Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Fri, 16 Sep 2022 16:57:49 +0200 Subject: [PATCH] fspath: change remote name regex to not match when leading/trailing space --- fs/fspath/path.go | 2 +- fs/fspath/path_test.go | 48 ++++++++++++++++-------------------------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/fs/fspath/path.go b/fs/fspath/path.go index 26575f725..6b8617feb 100644 --- a/fs/fspath/path.go +++ b/fs/fspath/path.go @@ -13,7 +13,7 @@ import ( ) const ( - configNameRe = `[\w. -]+` + configNameRe = `[\w.-]+(?: +[\w.-]+)*` ) var ( diff --git a/fs/fspath/path_test.go b/fs/fspath/path_test.go index c72423c0c..9d80ec4a8 100644 --- a/fs/fspath/path_test.go +++ b/fs/fspath/path_test.go @@ -38,9 +38,9 @@ func TestCheckConfigName(t *testing.T) { {"..", nil}, {".r.e.m.o.t.e.", nil}, {"rem ote", nil}, - {"remote ", nil}, - {" remote", nil}, - {" remote ", nil}, + {"remote ", errInvalidCharacters}, + {" remote", errInvalidCharacters}, + {" remote ", errInvalidCharacters}, } { got := CheckConfigName(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-emote-:", nil}, {"rem ote:", nil}, - {"remote :", nil}, - {" remote:", nil}, - {" remote :", nil}, + {"remote :", errInvalidCharacters}, + {" remote:", errInvalidCharacters}, + {" remote :", errInvalidCharacters}, {"", errInvalidCharacters}, {"rem:ote", errInvalidCharacters}, {"rem:ote:", errInvalidCharacters}, @@ -226,26 +226,14 @@ func TestParse(t *testing.T) { Path: "/path/to/file", }, }, { - in: "remote :/path/to/file", - wantParsed: Parsed{ - ConfigString: "remote ", - Name: "remote ", - Path: "/path/to/file", - }, + in: "remote :/path/to/file", + wantErr: errInvalidCharacters, }, { - in: " remote:/path/to/file", - wantParsed: Parsed{ - ConfigString: " remote", - Name: " remote", - Path: "/path/to/file", - }, + in: " remote:/path/to/file", + wantErr: errInvalidCharacters, }, { - in: " remote :/path/to/file", - wantParsed: Parsed{ - ConfigString: " remote ", - Name: " remote ", - Path: "/path/to/file", - }, + in: " remote :/path/to/file", + wantErr: errInvalidCharacters, }, { in: "rem#ote:/path/to/file", wantErr: errInvalidCharacters, @@ -482,9 +470,9 @@ func TestSplitFs(t *testing.T) { {"rem.ote:potato/sausage", "rem.ote:", "potato/sausage", nil}, {"rem ote:", "rem ote:", "", nil}, - {"remote :", "remote :", "", nil}, - {" remote:", " remote:", "", nil}, - {" remote :", " remote :", "", nil}, + {"remote :", "", "", errInvalidCharacters}, + {" remote:", "", "", errInvalidCharacters}, + {" remote :", "", "", errInvalidCharacters}, {".:", ".:", "", nil}, {"..:", "..:", "", nil}, @@ -539,9 +527,9 @@ func TestSplit(t *testing.T) { {"rem.ote:potato/sausage", "rem.ote:potato/", "sausage", nil}, {"rem ote:", "rem ote:", "", nil}, - {"remote :", "remote :", "", nil}, - {" remote:", " remote:", "", nil}, - {" remote :", " remote :", "", nil}, + {"remote :", "", "", errInvalidCharacters}, + {" remote:", "", "", errInvalidCharacters}, + {" remote :", "", "", errInvalidCharacters}, {".:", ".:", "", nil}, {"..:", "..:", "", nil},