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

Fix auto-atomicity for loops around required one/notone/set loops #56735

Merged
merged 1 commit into from
Aug 9, 2021

Conversation

stephentoub
Copy link
Member

Given an expression like (?:a{2,3}){2}, we currently erroneously convert that to (?>a{2,3}){2}, i.e. making the inner loop atomic, even though that then causes this to fail to match aaaa when it should match it (it fails because the first iteration will atomically match aaa and thus won't given any back, and then the next iteration will fail to match at least two as).

The simple fix is in FindLastExpressionInLoopForAutoAtomic, removing the special-case that tries to make the body of a loop that's a one/notone/set loop atomic. There are likely special-cases of this special-case that are still valid, but I'm not convinced it's worth trying to maintain and risk other gaps.

Fixes #56721
cc: @dotnet/area-system-text-regularexpressions, @anreton

Given an expression like `(?:a{2,3}){2}`, we currently erroneously convert that to `(?>a{2,3}){2}`, i.e. making the inner loop atomic, even though that then causes this to fail to match `aaaa` when it should match it (it fails because the first iteration will atomically match `aaa` and thus won't given any back, and then the next iteration will fail to match at least two `a`s).

The simple fix is in FindLastExpressionInLoopForAutoAtomic, removing the special-case that tries to make the body of a loop that's a one/notone/set loop atomic.  There are likely special-cases of this special-case that are still valid, but I'm not convinced it's worth trying to maintain and risk other gaps.
@ghost
Copy link

ghost commented Aug 2, 2021

Tagging subscribers to this area: @eerhardt, @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Issue Details

Given an expression like (?:a{2,3}){2}, we currently erroneously convert that to (?>a{2,3}){2}, i.e. making the inner loop atomic, even though that then causes this to fail to match aaaa when it should match it (it fails because the first iteration will atomically match aaa and thus won't given any back, and then the next iteration will fail to match at least two as).

The simple fix is in FindLastExpressionInLoopForAutoAtomic, removing the special-case that tries to make the body of a loop that's a one/notone/set loop atomic. There are likely special-cases of this special-case that are still valid, but I'm not convinced it's worth trying to maintain and risk other gaps.

Fixes #56721
cc: @dotnet/area-system-text-regularexpressions, @anreton

Author: stephentoub
Assignees: -
Labels:

area-System.Text.RegularExpressions

Milestone: -

@pgovind
Copy link

pgovind commented Aug 5, 2021

Just FYI, I usually debug your Regex PRs locally so I can see what is going on. Don't have time until at least tomorrow to try out this PR. Will review this PR Friday or early next week

@stephentoub
Copy link
Member Author

Thanks.

Copy link

@pgovind pgovind left a comment

Choose a reason for hiding this comment

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

Ok, LGTM! Ship it!

@danmoseley danmoseley merged commit ec31d60 into dotnet:main Aug 9, 2021
@danmoseley
Copy link
Member

#57102

@ghost ghost locked as resolved and limited conversation to collaborators Sep 9, 2021
@stephentoub stephentoub deleted the fixautoatomicity branch October 26, 2021 03:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regex: different result for Regex.Match in .NET 5.0 and .NET Framework 4.7.2
3 participants