-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C#: Fix glob pattern processing: allow **/
to match empty string
#16895
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,8 +76,20 @@ bool HasCharAt(int i, Predicate<char> p) => | |
throw new InvalidFilePatternException(pattern, "'**' preceeded by non-`/` character."); | ||
if (HasCharAt(i + 2, c => c != '/')) | ||
throw new InvalidFilePatternException(pattern, "'**' succeeded by non-`/` character"); | ||
sb.Append(".*"); | ||
i += 2; | ||
|
||
if (i + 2 < pattern.Length) | ||
{ | ||
// Processing .../**/... | ||
sb.Append("(.*/|)"); | ||
i += 3; | ||
} | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this case? if (i + 2 < pattern.Length)
{
// Processing .../**/...
sb.Append("(.*/|)");
}
i += 3; If adding three to the index puts the pointer at the end of the pattern we are parsing then we break out of the loop and append There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would also work, but I slightly prefer to handle this case explicitly. I think it's going to be easier to understand and maintain going forward. |
||
{ | ||
// Processing .../** | ||
sb.Append(".*"); | ||
// There's no need to add another .* to the end outside the loop, we can return early. | ||
return sb; | ||
} | ||
} | ||
else | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had took look at this a while for parsing it: It is an alternation construct that matches any sequence of characters that ends with
/
OR "nothing".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the idea.