mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
lib/ignore: Add directory separator to glob.Compile call
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3674 LGTM: calmh
This commit is contained in:
parent
d9040f8038
commit
7c37301c91
@ -279,14 +279,14 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
|
||||
var err error
|
||||
if strings.HasPrefix(line, "/") {
|
||||
// Pattern is rooted in the current dir only
|
||||
pattern.match, err = glob.Compile(line[1:])
|
||||
pattern.match, err = glob.Compile(line[1:], '/')
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
||||
}
|
||||
patterns = append(patterns, pattern)
|
||||
} else if strings.HasPrefix(line, "**/") {
|
||||
// Add the pattern as is, and without **/ so it matches in current dir
|
||||
pattern.match, err = glob.Compile(line)
|
||||
pattern.match, err = glob.Compile(line, '/')
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
||||
}
|
||||
@ -294,7 +294,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
|
||||
|
||||
line = line[3:]
|
||||
pattern.pattern = line
|
||||
pattern.match, err = glob.Compile(line)
|
||||
pattern.match, err = glob.Compile(line, '/')
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
||||
}
|
||||
@ -310,7 +310,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
|
||||
} else {
|
||||
// Path name or pattern, add it so it matches files both in
|
||||
// current directory and subdirs.
|
||||
pattern.match, err = glob.Compile(line)
|
||||
pattern.match, err = glob.Compile(line, '/')
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
||||
}
|
||||
@ -318,7 +318,7 @@ func parseIgnoreFile(fd io.Reader, currentFile string, seen map[string]bool) ([]
|
||||
|
||||
line := "**/" + line
|
||||
pattern.pattern = line
|
||||
pattern.match, err = glob.Compile(line)
|
||||
pattern.match, err = glob.Compile(line, '/')
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
||||
}
|
||||
|
@ -737,3 +737,35 @@ func TestIssue3639(t *testing.T) {
|
||||
t.Error("Should not match 'foo'")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue3674(t *testing.T) {
|
||||
stignore := `
|
||||
a*b
|
||||
a**c
|
||||
`
|
||||
|
||||
testcases := []struct {
|
||||
file string
|
||||
matches bool
|
||||
}{
|
||||
{"ab", true},
|
||||
{"asdfb", true},
|
||||
{"ac", true},
|
||||
{"asdfc", true},
|
||||
{"as/db", false},
|
||||
{"as/dc", 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user