Skip to content

Commit

Permalink
fix patterns that start with alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatcuk committed Dec 2, 2019
1 parent 18e4d62 commit 8fcc087
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions doublestar.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,23 @@ func Glob(pattern string) (matches []string, err error) {
return nil, nil
}

// if the pattern starts with alternatives, we need to handle that here - the
// alternatives may be a mix of relative and absolute
if pattern[0] == '{' {
options, endOptions := splitAlternatives(pattern[1:])
if endOptions == -1 {
return nil, ErrBadPattern
}
for _, o := range options {
m, e := Glob(o + pattern[endOptions+1:])
if e != nil {
return nil, e
}
matches = append(matches, m...)
}
return matches, nil
}

// If the pattern is relative or absolute and we're on a non-Windows machine,
// volumeName will be an empty string. If it is absolute and we're on a
// Windows machine, volumeName will be a drive letter ("C:") for filesystem
Expand Down
4 changes: 4 additions & 0 deletions doublestar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ var matchTests = []MatchTest{
{"{a/{b,c},abc}", "a/c", true, nil, true},
{"{a/{b,c},abc}", "abc", true, nil, true},
{"{a/{b,c},abc}", "a/b/c", false, nil, true},
{"{a/ab*}", "a/abc", true, nil, true},
{"{a/*}", "a/b", true, nil, true},
{"{a/abc}", "a/abc", true, nil, true},
{"{a/b,a/c}", "a/c", true, nil, true},
{"abc/**", "abc/b", true, nil, true},
{"**/abc", "abc", true, nil, true},
{"abc**", "abc/b", false, nil, true},
Expand Down

0 comments on commit 8fcc087

Please sign in to comment.