filter: Fix glob matching on absolute path marker on windows

A pattern part containing "/" is used to mark a path or a pattern as
absolute. However, on Windows the path separator is "\" such that glob
patterns like "?" could match the marker. The code now explicitly skips
the marker when the pattern does not represent an absolute path.
This commit is contained in:
Michael Eischer 2020-10-09 16:11:05 +02:00
parent 740758a5fa
commit 88c8e903d2
1 changed files with 5 additions and 1 deletions

View File

@ -167,13 +167,17 @@ func match(patterns Pattern, strs []string) (matched bool, err error) {
}
if len(patterns) <= len(strs) {
minOffset := 0
maxOffset := len(strs) - len(patterns)
// special case absolute patterns
if patterns[0].pattern == "/" {
maxOffset = 0
} else if strs[0] == "/" {
// skip absolute path marker if pattern is not rooted
minOffset = 1
}
outer:
for offset := maxOffset; offset >= 0; offset-- {
for offset := maxOffset; offset >= minOffset; offset-- {
for i := len(patterns) - 1; i >= 0; i-- {
var ok bool