Skip to content
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

Merged

Conversation

tamasvajk
Copy link
Contributor

This PR adjusts the path include/exclude logic to allow **/ to match an empty string. This means that **/src/ will match the content of the src folder in the root of the repository, while previously it only matched src folders in subdirectories.

@github-actions github-actions bot added the C# label Jul 3, 2024
@tamasvajk tamasvajk marked this pull request as ready for review July 3, 2024 06:57
@tamasvajk tamasvajk requested a review from a team as a code owner July 3, 2024 06:57
hvitved
hvitved previously approved these changes Jul 3, 2024
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

if (i + 2 < pattern.Length)
{
// Processing .../**/...
sb.Append("(.*/|)");
Copy link
Contributor

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".

Copy link
Contributor Author

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.

sb.Append("(.*/|)");
i += 3;
}
else
Copy link
Contributor

@michaelnebel michaelnebel Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this case?
What about

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 .*

Copy link
Contributor Author

@tamasvajk tamasvajk Jul 3, 2024

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tamasvajk tamasvajk merged commit 456c649 into github:main Jul 4, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants