-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 handling of capture groups inside of negative lookarounds #97463
Fix handling of capture groups inside of negative lookarounds #97463
Conversation
The Regex compiler and source generator weren't uncapturing captures inside of a negative lookaround. That then leads both to subsequent backreferences matching when they shouldn't.
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue DetailsThe Regex compiler and source generator weren't uncapturing captures inside of a negative lookaround. That then leads both to subsequent backreferences matching when they shouldn't. Fixes #97455
|
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.
Seems reasonable - I assume these tests still run and pass on .NET Framework..?
No analogous issue with positive lookarounds? |
Yes |
No, those captures are supposed to persist (and do). |
@@ -114,6 +118,8 @@ private static IEnumerable<(string Pattern, string Input, RegexOptions Options, | |||
yield return (@"(?<=\d?)a{4}", "123aaaaaaaaa", RegexOptions.None, 0, 12, true, "aaaa"); | |||
yield return (@"(?<=a{3,5}[ab]*)1234", "aaaaaaa1234", RegexOptions.None, 0, 11, true, "1234"); | |||
yield return (@"(\w)*?3(?<=33)$", "1233", RegexOptions.None, 0, 4, true, "1233"); | |||
yield return (@"(?=(\d))4\1", "44", RegexOptions.None, 0, 2, true, "44"); | |||
yield return (@"(?=(\d))4\1", "43", RegexOptions.None, 0, 2, false, ""); | |||
|
|||
// Zero-width negative lookbehind assertion: Actual - "(\\w){6}(?<!XXX)def" | |||
yield return (@"(\w){6}(?<!XXX)def", "XXXabcdef", RegexOptions.None, 0, 9, true, "XXXabcdef"); |
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.
@stephentoub are we covered for testing analogous case for negative lookbehind? eg., (?<!(b)a)\1
shouldn't match bb
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.
Probably not from a test perspective; the src fix covers both directions. Feel free to submit a pr.
does https://regex101.com/r/jsQ12z/1 mean that regex101 is still using 6.0? |
More likely is it's using the interpreter |
The Regex compiler and source generator weren't uncapturing captures inside of a negative lookaround. That then leads both to subsequent backreferences matching when they shouldn't.
Fixes #97455