Skip to content

Fix SymbolixRegexRunner handling of "beginning" - #64946

Merged
stephentoub merged 1 commit into
dotnet:mainfrom
stephentoub:runnerbeginning
Feb 8, 2022
Merged

stephentoub merged 1 commit into
dotnet:mainfrom
stephentoub:runnerbeginning

Conversation

@stephentoub

@stephentoub stephentoub commented Feb 7, 2022 •

Copy link
Copy Markdown
Member

The Runner's Go implementation is loading the runtext but ignoring runtextbeg. If a non-0 beginning were passed in, the matcher could end up evaluating beginning anchors incorrectly, as it always considers beginning == 0. This fixes that by slicing the input to ensure the matcher is always called with a span representing the full beginning-end length, such that its beginning==0 assumption is true.

@joperezr, this will likely get cleaned up further with your span changes, assuming the calling Run/Scan loop ends up creating the span and passing that in, ensuring the span is always the full range such that runtextbeg and runtextend can be ignored.

cc: @olsaarik, @veanes

The Runner's Go implementation is loading the `runtext` but ignoring `runtextbeg`.  If a non-0 beginning were passed in, the matcher could end up evaluating beginning anchors incorrectly, as it always considers beginning == 0.  This fixes that by slicing the input to ensure the matcher is always called with a span representing the full beginning-end length, such that it's beginning==0 assumption is true.
@ghost

ghost commented Feb 7, 2022

Copy link
Copy Markdown

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 Runner's Go implementation is loading the runtext but ignoring runtextbeg. If a non-0 beginning were passed in, the matcher could end up evaluating beginning anchors incorrectly, as it always considers beginning == 0. This fixes that by slicing the input to ensure the matcher is always called with a span representing the full beginning-end length, such that it's beginning==0 assumption is true.

@joperezr, this will likely get cleaned up further with your span changes, assuming the calling Run/Scan loop ends up creating the span and passing that in, ensuring the span is always the full range such that runtextbeg and runtextend can be ignored.

cc: @olsaarik, @veanes

Author: stephentoub
Assignees: -
Labels:

area-System.Text.RegularExpressions

Milestone: 7.0.0

@ghost ghost assigned stephentoub Feb 7, 2022
@olsaarik

olsaarik commented Feb 7, 2022

Copy link
Copy Markdown
Contributor

Great, you found it :) I looked over the changes and looks good to me.

@joperezr joperezr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@joperezr

joperezr commented Feb 7, 2022

Copy link
Copy Markdown
Member

@joperezr, this will likely get cleaned up further with your span changes, assuming the calling Run/Scan loop ends up creating the span and passing that in, ensuring the span is always the full range such that runtextbeg and runtextend can be ignored.

Yup, that is exactly what my PR is doing: https://github.com/dotnet/runtime/pull/62509/files#diff-76183069218af46fc69f0126ba5d6a921355be2714c67a77b89429a92fd98945R403-R408
Basically, Run() will pass to all engines a sliced span that just has beginning..end contents, and then for the resulting match it will update the indexes in case beginning was other than 0. I will refactor my current PR once this goes in so that changes don't conflict, but essentially the logic added by this PR won't be required any longer since Run() will be doing it instead.

@stephentoub
stephentoub merged commit 8ee59f4 into dotnet:main Feb 8, 2022
@stephentoub
stephentoub deleted the runnerbeginning branch February 8, 2022 04:02
@danmoseley

Copy link
Copy Markdown
Contributor

Remind me, if/when look behind asserts are supported, will this need revisiting (as those can look past the beginning)?

@veanes

veanes commented Feb 8, 2022

Copy link
Copy Markdown
Contributor

I think it will be an orthogonal issue. Lookaround in NonBacktracking will essentially be another (incrementally created) DFA that walks backwards or forwards from the current position, more or less independent of other features (or I expect it to be independent) even supporting the same features inside the lookaround regex itself (e.g. anchors inside a lookback)

@stephentoub

stephentoub commented Feb 8, 2022 •

Copy link
Copy Markdown
Member Author

(as those can look past the beginning)?

No, they can't. They can look behind startat, but not behind beginning. There's nothing before the beginning.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 10, 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.

5 participants