lib/ignore: Only handle lines prefixed with #include specially (fixes #4680)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4684
LGTM: AudriusButkevicius, calmh
This commit is contained in:
Simon Frei
2018-01-17 16:56:53 +00:00
committed by Jakob Borg
parent e147db5233
commit a1761795fe
2 changed files with 39 additions and 15 deletions
+27 -1
View File
@@ -186,7 +186,6 @@ func TestBadPatterns(t *testing.T) {
"**/[",
"#include nonexistent",
"#include .stignore",
"!#include makesnosense",
}
for _, pat := range badPatterns {
@@ -930,3 +929,30 @@ func TestDuplicateLines(t *testing.T) {
t.Fatalf("Parsed patterns differ when manually removing duplicate lines")
}
}
func TestIssue4680(t *testing.T) {
stignore := `
#snapshot
`
testcases := []struct {
file string
matches bool
}{
{"#snapshot", true},
{"#snapshot/foo", true},
}
pats := New(fs.NewFilesystem(fs.FilesystemTypeBasic, "."), WithCache(true))
err := pats.Parse(bytes.NewBufferString(stignore), ".stignore")
if err != nil {
t.Fatal(err)
}
for _, tc := range testcases {
res := pats.Match(tc.file).IsIgnored()
if res != tc.matches {
t.Errorf("Matches(%q) == %v, expected %v", tc.file, res, tc.matches)
}
}
}