fixes #88 Globstar matches zero directories #89
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addressing the issue raised in #88
Summary of the issue
In the current implementation,
doublestar.Match("a/**/", "a")
anddoublestar.Match("a/**/", "a/")
both returnfalse
.Bash shopt docs say that
**
followed by a/
will match zero or more directories and subdirectories.Bash 5.2 implementation confirms this behavior:
What changed?
Changed
isZeroLengthPattern
inmatch.go
to recognize**/
and/**/
as zero length patterns, in addition to/**
,*
, and**
.How was this tested?
Added two new test cases to
matchTests
indoublestar_test.go
:{"a/**/", "a", true, true, nil, false, false, false, false, 4, 4}
. This test case verifies that/**/
is a zero length pattern.{"a/**/", "a/", true, true, nil, false, false, false, false, 4, 4}
This test case verifies that**/
is a zero length pattern. I was less certain whether**/
should be considered a zero length pattern; but it's the only way I came up with to make this test case pass. And it felt wrong to omit this test case, since there's already a very similar test case with a successful match{"a/**", "a/", true, true, nil, false, false, false, false, 7, 7}
I wanted to also run these tests on disk but the current implementation of
FilepathGlob
inutils.go
makes it impossible and changing its implementation is outside of the scope of this change. The issue there is on this line:doublestar/utils.go
Line 87 in 465a339
This line removes the trailing
/
from a pattern likea/**/
which changes its meaning.a/**/
matches zero or more directories and subdirectories at patha/
.a/**
matches all files, and zero or more directories and subdirectories at patha/
.Luckily, with
GlobWalk
I can add an additional filtering function for each match so that I can ensure that the pattern that I use matches only directories and not regular files.