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
|
var err error
|
||||||
if strings.HasPrefix(line, "/") {
|
if strings.HasPrefix(line, "/") {
|
||||||
// Pattern is rooted in the current dir only
|
// 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 {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
||||||
}
|
}
|
||||||
patterns = append(patterns, pattern)
|
patterns = append(patterns, pattern)
|
||||||
} else if strings.HasPrefix(line, "**/") {
|
} else if strings.HasPrefix(line, "**/") {
|
||||||
// Add the pattern as is, and without **/ so it matches in current dir
|
// 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 {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
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:]
|
line = line[3:]
|
||||||
pattern.pattern = line
|
pattern.pattern = line
|
||||||
pattern.match, err = glob.Compile(line)
|
pattern.match, err = glob.Compile(line, '/')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
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 {
|
} else {
|
||||||
// Path name or pattern, add it so it matches files both in
|
// Path name or pattern, add it so it matches files both in
|
||||||
// current directory and subdirs.
|
// current directory and subdirs.
|
||||||
pattern.match, err = glob.Compile(line)
|
pattern.match, err = glob.Compile(line, '/')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
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
|
line := "**/" + line
|
||||||
pattern.pattern = line
|
pattern.pattern = line
|
||||||
pattern.match, err = glob.Compile(line)
|
pattern.match, err = glob.Compile(line, '/')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid pattern %q in ignore file (%v)", line, err)
|
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'")
|
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…
x
Reference in New Issue
Block a user