dazinator / DotNet.Glob

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

Defect: Spaces After Comma Doesn't Match #31

Closed MarkMichaelis closed 7 years ago

MarkMichaelis commented 7 years ago

The following results seems to indicate a defect:

Am I missing something?

dazinator commented 7 years ago

Interesting.. looks like you may have found a bug there. Are you using the latest stable nuget version? If you have time to submit / add a failing test case to the tests project I'd be greatful. I'll take a look as soon as I can.

MarkMichaelis commented 7 years ago

It appears the issue is with the comma, not just the space: DotNet.Globbing.Glob.Parse("Stuff,X*").IsMatch("Stuff,Xx")': false

dazinator commented 7 years ago

Hmm

Does this match (added an extra space)

DotNet.Globbing.Glob.Parse("Stuff,X* ").IsMatch("Stuff,Xx")'`

?

MarkMichaelis commented 7 years ago

Fortunately, no.

dazinator commented 7 years ago

Or this:

DotNet.Globbing.Glob.Parse("Stuff,X*").IsMatch("Stuff,Xx ")'`

dazinator commented 7 years ago

My guess (not at pc right now) is that it happens if:

  1. The pattern ends in a *
  2. The test string is close to the minimum length it can be for a successful match

Hence why i'm wondering If making the test string one char longer suddenly matches..

I will get to the bottom of it a bit later!!

dazinator commented 7 years ago

Ok I see what is happening here. This is related to #32

When unsupported alpha numeric characters are encountered in the token (comma is one of those i'm afraid) the parsing / tokeniser is skipping past that unsupported character so it's essentially like it's not there in the pattern.

In other words, when you do this:

DotNet.Globbing.Glob.Parse("Stuff,*").IsMatch("Stuff, x");: true

you are actually getting the result of this:

DotNet.Globbing.Glob.Parse("Stuff*").IsMatch("Stuff, x");: true

Because the comma in the pattern is being skipped over.

I need to think about how I address this. The first thing I should do is throw an exception if there is an unsupported character used in a token. If you don't mind I am going to close this in favour of #32