lib/ignore: Don't match root (".")

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4122
This commit is contained in:
Simon Frei 2017-05-01 16:58:08 +00:00 committed by Jakob Borg
parent 9de6cdddfd
commit 0b854dff9d
2 changed files with 30 additions and 1 deletions

View File

@ -163,7 +163,7 @@ func (m *Matcher) patternsUnchanged(file string) bool {
}
func (m *Matcher) Match(file string) (result Result) {
if m == nil {
if m == nil || file == "." {
return resultNotMatched
}

View File

@ -843,3 +843,32 @@ func TestIsInternal(t *testing.T) {
}
}
}
func TestRoot(t *testing.T) {
stignore := `
!/a
/*
`
testcases := []struct {
file string
matches bool
}{
{".", false},
{"a", false},
{"b", true},
}
pats := New(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)
}
}
}