dazinator / DotNet.Glob

A fast globbing library for .NET / .NETStandard applications. Outperforms Regex.
MIT License
363 stars 27 forks source link

Having a dot after a wildcard in a pattern that also has literal directory and wildcard directory matchers can fail to match a valid path #87

Closed TheFieryScythe closed 3 years ago

TheFieryScythe commented 3 years ago

This is an oddly specific failure case that I believe should be successfully matching:

bool TestMatch(string pattern)
{
    return Glob.Parse(pattern).IsMatch("/some/path/some.file.exe");
}

TestMatch("**/*").Should().BeTrue();
TestMatch("**/some/path/*").Should().BeTrue();
TestMatch("**/some/path/**/*").Should().BeTrue();

TestMatch("**/some.file.exe").Should().BeTrue();
TestMatch("**/some.*.exe").Should().BeTrue();
TestMatch("**/some.file*exe").Should().BeTrue();
TestMatch("**/some.file*.exe").Should().BeTrue();

TestMatch("/some/path/some.file.exe").Should().BeTrue();
TestMatch("/some/path/some.*.exe").Should().BeTrue();
TestMatch("/some/path/some.file*exe").Should().BeTrue();
TestMatch("/some/path/some.file*.exe").Should().BeTrue();

TestMatch("/some/path/**/some.file.exe").Should().BeTrue();
TestMatch("/some/path/**/some.*.exe").Should().BeTrue();
TestMatch("/some/path/**/some.file*exe").Should().BeTrue();
TestMatch("/some/path/**/some.file*.exe").Should().BeTrue(); // Fails to match

TestMatch("**/some/path/some.file.exe").Should().BeTrue();
TestMatch("**/some/path/some.*.exe").Should().BeTrue();
TestMatch("**/some/path/some.file*exe").Should().BeTrue();
TestMatch("**/some/path/some.file*.exe").Should().BeTrue(); // Fails to match

This has been tested and occurs on the 3.1.2 nuget package and the 3.2.0-alpha.33 package.

dazinator commented 3 years ago

Weird. Thanks for reporting I will see if I can replicate and work out what's going wrong.

dazinator commented 3 years ago

@TheFieryScythe - sorry for the delay in fixing this, have been a little busy of late. There was indeed a niche bug with how ** works. When it was not the last part of the pattern, and it also was not required to actually consume any matching text (in otherwords, in situations where you could remove ** from the pattern and still end up matching the same text!) - then it was failing to match in situations that were valid matches.

I've fixed this in 3.1.3 (and latest alpha) and included the two tests above as regression tests for the future. Thanks for taking the time to submit an issue.