Skip to content

Commit

Permalink
Globstar matches zero directories
Browse files Browse the repository at this point in the history
  • Loading branch information
mmxmb authored and bmatcuk committed Oct 21, 2023
1 parent 465a339 commit 5df0d9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doublestar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ var matchTests = []MatchTest{
{"[abc]", "b", true, true, nil, false, false, true, true, 3, 3},
{"**", "", true, true, nil, false, false, false, false, 38, 38},
{"a/**", "a", true, true, nil, false, false, false, true, 7, 7},
{"a/**/", "a", true, true, nil, false, false, false, false, 4, 4},
{"a/**", "a/", true, true, nil, false, false, false, false, 7, 7},
{"a/**/", "a/", true, true, nil, false, false, false, false, 4, 4},
{"a/**", "a/b", true, true, nil, false, false, false, true, 7, 7},
{"a/**", "a/b/c", true, true, nil, false, false, false, true, 7, 7},
{"**/c", "c", true, true, nil, !onWindows, false, false, true, 5, 4},
Expand Down
11 changes: 8 additions & 3 deletions match.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,14 @@ MATCH:
}

func isZeroLengthPattern(pattern string, separator rune) (ret bool, err error) {
// `/**` is a special case - a pattern such as `path/to/a/**` *should* match
// `path/to/a` because `a` might be a directory
if pattern == "" || pattern == "*" || pattern == "**" || pattern == string(separator)+"**" {
// `/**`, `**/`, and `/**/` are special cases - a pattern such as `path/to/a/**` or `path/to/a/**/`
// *should* match `path/to/a` because `a` might be a directory
if pattern == "" ||
pattern == "*" ||
pattern == "**" ||
pattern == string(separator)+"**" ||
pattern == "**"+string(separator) ||
pattern == string(separator)+"**"+string(separator) {
return true, nil
}

Expand Down

0 comments on commit 5df0d9d

Please sign in to comment.