diff --git a/lib/ignore/ignore.go b/lib/ignore/ignore.go index 7578446ba..cbc56b13d 100644 --- a/lib/ignore/ignore.go +++ b/lib/ignore/ignore.go @@ -422,6 +422,10 @@ func parseLine(line string) ([]Pattern, error) { } } + if line == "" { + return nil, errors.New("missing pattern") + } + if pattern.result.IsCaseFolded() { line = strings.ToLower(line) } diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go index 462f88a31..1de1e305d 100644 --- a/lib/ignore/ignore_test.go +++ b/lib/ignore/ignore_test.go @@ -14,6 +14,7 @@ import ( "os" "path/filepath" "runtime" + "strings" "testing" "time" @@ -1150,3 +1151,20 @@ func TestSkipIgnoredDirs(t *testing.T) { t.Error("SkipIgnoredDirs should be true") } } + +func TestEmptyPatterns(t *testing.T) { + // These patterns are all invalid and should be rejected as such (without panicking...) + tcs := []string{ + "!", + "(?d)", + "(?i)", + } + + for _, tc := range tcs { + m := New(fs.NewFilesystem(fs.FilesystemTypeFake, "")) + err := m.Parse(strings.NewReader(tc), ".stignore") + if err == nil { + t.Error("Should reject invalid pattern", tc) + } + } +}