lib/fs: Be even more strict about Windows names (ref #7008) (#7012)

Things like nul.whatever.txt are also not allowed.
This commit is contained in:
Jakob Borg
2020-09-28 10:42:37 +02:00
committed by GitHub
parent 9e0b924d57
commit e6b1f67ecf
2 changed files with 48 additions and 13 deletions
+26
View File
@@ -44,3 +44,29 @@ func TestCommonPrefix(t *testing.T) {
test(`Audrius`, `Audrius`, `Audrius`)
test(`.`, `.`, `.`)
}
func TestWindowsInvalidFilename(t *testing.T) {
cases := []struct {
name string
err error
}{
{`asdf.txt`, nil},
{`nul`, errInvalidFilenameWindowsReservedName},
{`nul.txt`, errInvalidFilenameWindowsReservedName},
{`nul.jpg.txt`, errInvalidFilenameWindowsReservedName},
{`some.nul.jpg`, nil},
{`foo>bar.txt`, errInvalidFilenameWindowsReservedChar},
{`foo \bar.txt`, errInvalidFilenameWindowsSpacePeriod},
{`foo.\bar.txt`, errInvalidFilenameWindowsSpacePeriod},
{`foo.d\bar.txt`, nil},
{`foo.d\bar .txt`, nil},
{`foo.d\bar. txt`, nil},
}
for _, tc := range cases {
err := WindowsInvalidFilename(tc.name)
if err != tc.err {
t.Errorf("For %q, got %v, expected %v", tc.name, err, tc.err)
}
}
}