mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
Instead of panicking when we try to look closer at the empty pattern, return something like `invalid pattern "(?d)" in ignore file: missing pattern`.
This commit is contained in:
parent
ac3879e2b0
commit
e0d4cdc9a3
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user