dazinator / DotNet.Glob

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

/DIR1/DIR2/file.txt won't match glob /DIR1/*/* #21

Closed PeAb closed 7 years ago

PeAb commented 7 years ago

Code example:

Glob glob = Glob.Parse(@"/DIR1/*/*");
MatchInfo matchInfo = glob.Match(@"/DIR1/DIR2/file.txt");
Console.Out.WriteLine("matchInfo.Success = {0}", matchInfo.Success);

gives: matchInfo.Success = False

dazinator commented 7 years ago

Thanks for reporting. The algortihms for IsMatch and Match are slightly different. Basically because Match() attempts to get additional information and so it does additional analysis, where as IsMatch() always attempts to fail fast if things don't match. I'll need to check if this is a problem just for Match() or if it also effects IsMatch. I'll add a couple of tests cases for this.

dazinator commented 7 years ago

Ok, this is fixed in latest build I have extended the tests a bit, and included this as a regression test. Latest nuget package if you want to re-test is: https://www.nuget.org/packages/DotNet.Glob/1.5.0-unstable0014

Thanks

PeAb commented 7 years ago

Thanks, that fixed it. Although in the testcase below:

Glob glob = Glob.Parse(@"/DIR1/ab*d.txt"); string s = @"/DIR1/ab.txt"; bool isMatch = glob.IsMatch(s); Console.Out.WriteLine("isMatch = {0}", isMatch); MatchInfo matchInfo = glob.Match(s); Console.Out.WriteLine("matchInfo.Success = {0}", matchInfo.Success);

The results are: glob.IsMatch(s) works and returns False ...but glob.Match(s) generates a System.IndexOutOfRangeException

dazinator commented 7 years ago

Ok thanks, I'll add that to the test cases and will fix that shortly.

dazinator commented 7 years ago

Just wondering, do you actually need Match() as opposed to IsMatch() ?

I ask because I'm tempted to drop this method until it can be written in a way that ensure it behaves identically to IsMatch.

PeAb commented 7 years ago

I really only use IsMatch() currently.

dazinator commented 7 years ago

Closing this, will open a new issue to get rid of Match().