Fix bug with multiline regexp and right anchor #13200
Open
+16
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://bugs.ruby-lang.org/issues/21291
This seems to be an optimization bug. With
ONIG_DONT_OPTIMIZE
defined,"aa\n" =~ /$.*/m
returns 2 as the bug report author expected. But with optimizations turned on it does not find a match.The optimization involves setting
ANCHOR_ANYCHAR_STAR_ML
, which ultimately limits the regexp search to the starting position. But in this case, because of the right anchor, we won't find a match at the starting position. We need to keep searching, and that is what happens when the optimization is disabled.This commit adds the anchor information to the env, so we can skip the optimization when we've seen a right anchor prior to the quantifier.