dazinator / DotNet.Glob

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

endless loop in version 1.6.6 #37

Closed thomas-patzig closed 7 years ago

thomas-patzig commented 7 years ago

try this code: localPattern="C:\sources\COMPILE*\MSVC120.DLL" localInput="C:\sources\COMPILE\ANTLR3.RUNTIME.DLL"

var glob = Glob.Parse( localPattern ); return glob.IsMatch( localInput );

endless loop in "WildcardDirectoryTokenEvaluator.IsMatch":

currentPosition=51 maxPos=51 isMatch=false

` // Match until maxpos, is reached. while (currentPosition <= maxPos) { // Test at current position. isMatch = _subEvaluator.IsMatch(allChars, currentPosition, out newPosition); if (isMatch) { return isMatch; }

                // Iterate until we hit a seperator or maxPos.
                while (currentPosition < maxPos)
                {
                    currentPosition = currentPosition + 1;
                    currentChar = allChars[currentPosition];
                    if (currentChar == '/' || currentChar == '\\')
                    {
                        // advance past the seperator.
                        currentPosition = currentPosition + 1;
                        break;
                    }
                }
            }

`

dazinator commented 7 years ago

Ouch.. nasty! It seems I introduced this as a result of my last fix! I'll add a test case and fix this as soon as I can! Thanks

dazinator commented 7 years ago

Hmm I can't replicate this. I've added a test case using the pattern and test string you have supplied above but it passes. Could you provide a repro?

dazinator commented 7 years ago

I am closing this as I can't repro.

I created new console application and installed 1.6.6.

I then did this:

class Program
    {
        static void Main(string[] args)
        {
            string localPattern = @"C:\sources\COMPILE*\MSVC120.DLL";
            string localInput = @"C:\sources\COMPILE\ANTLR3.RUNTIME.DLL";

            bool isMAtch = DotNet.Globbing.Glob.Parse(localPattern).IsMatch(localInput);
            Console.WriteLine("IsMatch: " + isMAtch);
        }
    }

The output was:

image

thomas-patzig commented 7 years ago

try this code:

var x = Glob.Parse( @"C:\sources\x-y 1\BIN\DEBUG\COMPILE\**\MSVC*120.DLL" ); x.IsMatch( @"C:\sources\x-y 1\BIN\DEBUG\COMPILE\ANTLR3.RUNTIME.DLL" );

I think it's the blank space in path "x-y 1"

thomas-patzig commented 7 years ago

Hi dazinator,

do you reopen this issue or should I create a new one?

dazinator commented 7 years ago

Have reopened. I will investigate with the new test case you have provided, hopefully will catch the problem this time, thank you.

dazinator commented 7 years ago

Good news - I have replicated this using your last example - thank you. I will release an updated patch version to nuget.org momentarily.

dazinator commented 7 years ago

Fixed as of 1.6.9: https://www.nuget.org/packages/DotNet.Glob/1.6.9

thomas-patzig commented 7 years ago

it works thanks

dazinator commented 7 years ago

No problem. Thank you for reporting.