dazinator / DotNet.Glob

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

IsMatch throws IndexOutOfRangeException #44

Closed sualitu closed 6 years ago

sualitu commented 6 years ago

If I run:

var file = "x";
var glob = "**/y"
Glob.Parse(glob).IsMatch(file);

The following exception is thrown by IsMatch

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at DotNet.Globbing.Evaluation.WildcardDirectoryTokenEvaluator.IsMatch(String allChars, Int32 currentPosition, Int32& newPosition)
   at DotNet.Globbing.Evaluation.CompositeTokenEvaluator.IsMatch(String allChars, Int32 currentPosition, Int32& newPosition)
   at DotNet.Globbing.Glob.IsMatch(String subject)

It seems that if the length of the string to match is the same as what follows the **/ the exception is thrown.

Additional information:

λ dotnet --version
2.1.4
dazinator commented 6 years ago

may I ask what version of dotnet.glob nuget package you are using?

sualitu commented 6 years ago

Of course you may: <PackageReference Include="DotNet.Glob" Version="2.0.0" />

dazinator commented 6 years ago

Thanks, I will add a test case for this and hopefully, it will reproduce, in which case I'll get a fix out. Thanks for taking the time to report :-)

dazinator commented 6 years ago

I have fixed this in version 2.0.1 which has been uploaded to nuget. Thank you for finding this edge case :-)

sualitu commented 6 years ago

Fantastic work! Thank you for sorting this out so quickly :)