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 beginning fixups of captures after Regex span support #66713

Merged
merged 1 commit into from
Mar 16, 2022

Conversation

stephentoub
Copy link
Member

The Regex span support changed the scanning infrastructure to always be based on spans. That means that when a string is passed in by the caller, internally we still operate on it as a span. That also means we can take advantage of slicing, and if the caller has specified via a beginning/length set of arguments that we should only process a substring, we can just slice to that substring. That, however, then means that all offsets computed by the scanning implementation are 0-based rather than beginning-based. The span change included a fixup for the overall match position, but not for the position of each individual capture, and that then meant that captures were providing the wrong values. We unfortunately didn't have any tests for validating groups that also involved non-0 beginnings with string inputs.

Fixes #66697

The Regex span support changed the scanning infrastructure to always be based on spans.  That means that when a string is passed in by the caller, internally we still operate on it as a span.  That also means we can take advantage of slicing, and if the caller has specified via a beginning/length set of arguments that we should only process a substring, we can just slice to that substring.  That, however, then means that all offsets computed by the scanning implementation are 0-based rather than beginning-based.  The span change included a fixup for the overall match position, but not for the position of each individual capture, and that then meant that captures were providing the wrong values.  We unfortunately didn't have any tests for validating groups that also involved non-0 beginnings with string inputs.
@ghost
Copy link

ghost commented Mar 16, 2022

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

Issue Details

The Regex span support changed the scanning infrastructure to always be based on spans. That means that when a string is passed in by the caller, internally we still operate on it as a span. That also means we can take advantage of slicing, and if the caller has specified via a beginning/length set of arguments that we should only process a substring, we can just slice to that substring. That, however, then means that all offsets computed by the scanning implementation are 0-based rather than beginning-based. The span change included a fixup for the overall match position, but not for the position of each individual capture, and that then meant that captures were providing the wrong values. We unfortunately didn't have any tests for validating groups that also involved non-0 beginnings with string inputs.

Fixes #66697

Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Text.RegularExpressions

Milestone: -

Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

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

Thank you for fixing, sorry that I missed this from the beginning.

@stephentoub stephentoub merged commit be9c528 into dotnet:main Mar 16, 2022
@stephentoub stephentoub deleted the fixregexbeginning branch March 16, 2022 21:18
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Mar 30, 2022
The Regex span support changed the scanning infrastructure to always be based on spans.  That means that when a string is passed in by the caller, internally we still operate on it as a span.  That also means we can take advantage of slicing, and if the caller has specified via a beginning/length set of arguments that we should only process a substring, we can just slice to that substring.  That, however, then means that all offsets computed by the scanning implementation are 0-based rather than beginning-based.  The span change included a fixup for the overall match position, but not for the position of each individual capture, and that then meant that captures were providing the wrong values.  We unfortunately didn't have any tests for validating groups that also involved non-0 beginnings with string inputs.
@ghost ghost locked as resolved and limited conversation to collaborators Apr 16, 2022
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.

[dotnet-sdk-7.0.100-preview.3.22161.14] Regex.Match method return unexcepted Groups elements
3 participants