Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b77eb3

Browse files
committed
Merge branch 'hotfix/3.1.1'
2 parents3c09eba +0b470c1 commit0b77eb3

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

‎src/DotNet.Glob.Tests/GlobTests.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public class GlobTests
2727
[InlineData("range/[a-b][C-D]","range/ac","range/Ad","range/BD")]// Regression tests for https://github.com/dazinator/DotNet.Glob/issues/41
2828
[InlineData(@"abc/**",@"abcd")]
2929
[InlineData(@"**\segment1\**\segment2\**",@"C:\test\segment1\src\segment2")]
30-
[InlineData(@"**/.*","foobar.")]// Regression test for https://github.com/dazinator/DotNet.Glob/issues/78
30+
[InlineData(@"**/.*","foobar.")]// Regression test for https://github.com/dazinator/DotNet.Glob/issues/78
31+
[InlineData(@"**/~*","/")]// Regression test for https://github.com/dazinator/DotNet.Glob/issues/82
3132
publicvoidDoes_Not_Match(stringpattern,paramsstring[]testStrings)
3233
{
3334
varglob=Globbing.Glob.Parse(pattern);

‎src/DotNet.Glob/Evaluation/WildcardDirectoryTokenEvaluator.cs‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
2525
#endif
2626
{
2727
// We shortcut to success for a ** in some special cases:-
28-
// 1. The remaining tokens don't need to consume a minimum number of chracters in order to match.
28+
// 1. The remaining tokens don't need to consume a minimum number of chracters in order to match.
2929

3030
// We shortcut to failure for a ** in some special cases:-
3131
// A) The token was parsed with a leading path separator (i.e '/**' and the current charater we are matching from isn't a path separator.
3232

3333
newPosition=currentPosition;
34-
// bool matchedLeadingSeperator = false;
34+
// bool matchedLeadingSeperator = false;
3535

3636
// A) If leading seperator then current character needs to be that seperator.
3737
if(allChars.Length<=currentPosition||currentPosition<0)
@@ -40,7 +40,7 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
4040
}
4141
charcurrentChar=allChars[currentPosition];
4242
if(_token.LeadingPathSeparator!=null)
43-
{
43+
{
4444
if(!GlobStringReader.IsPathSeparator(currentChar))
4545
{
4646
// expected separator.
@@ -49,25 +49,26 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
4949
//else
5050
//{
5151
// advance current position to match the leading separator.
52-
// matchedLeadingSeperator = true;
52+
// matchedLeadingSeperator = true;
5353
currentPosition=currentPosition+1;
5454
//}
5555
}
5656
else
5757
{
58-
// no leading seperator,
59-
// means ** or possibly **/ used, not /**
58+
// no leading seperator, in which case match an optional leading seperator in string.
59+
60+
// means ** or possibly **/ used as pattern, not /**
6061
// Input string doesn't need to start with a / or \ but if it does, it will be matched.
6162
// i.e **/foo/bar will match foo/bar or /foo/bar.
6263
// where as /**/foo/bar will not match foo/bar it will only match /foo/bar.
63-
// currentChar = allChars[currentPosition];
64+
// currentChar = allChars[currentPosition];
6465
if(GlobStringReader.IsPathSeparator(currentChar))
6566
{
6667
// advance current position to match the leading separator.
67-
// matchedLeadingSeperator = true;
68-
currentPosition=currentPosition+1;
68+
// matchedLeadingSeperator = true;
69+
currentPosition=currentPosition+1;
6970
}
70-
}
71+
}
7172

7273
// 1. if no more tokens require matching we match.
7374
if(_subEvaluator.ConsumesMinLength==0)
@@ -79,6 +80,12 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
7980
// Because we know we have more tokens in the pattern (subevaluators) - those will require a minimum amount of characters to match (could be 0 too).
8081
// We can therefore calculate a "max" character position that we can match to, as if we exceed that position the remaining tokens cant possibly match.
8182
intmaxPos=(allChars.Length-_subEvaluator.ConsumesMinLength);
83+
84+
// Is there enough remaining characters to provide a match, if not exit early.
85+
if(currentPosition>maxPos)
86+
{
87+
returnfalse;
88+
}
8289

8390
// If all of the remaining tokens have a precise length, we can calculate the exact character that we need to macth to in the string.
8491
// Otherwise we have to test at multiple character positions until we find a match (less efficient)
@@ -131,7 +138,7 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
131138
if(!matchedSeperator)
132139
{
133140
returnfalse;
134-
}
141+
}
135142
}
136143

137144
isMatch=_subEvaluator.IsMatch(allChars,currentPosition,outnewPosition);
@@ -148,7 +155,7 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
148155
// Iterate until we hit the next separator or maxPos.
149156
matchedSeperator=false;
150157
while(currentPosition<maxPos)
151-
{
158+
{
152159
currentPosition=currentPosition+1;
153160
currentChar=allChars[currentPosition];
154161

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp