Skip to content

Fix bug with multiline regexp and right anchor #13200

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

composerinteralia
Copy link
Contributor

@composerinteralia composerinteralia commented Apr 29, 2025

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.

@composerinteralia
Copy link
Contributor Author

composerinteralia commented Apr 29, 2025

Oops, I must have messed something up before pushing. Let me try that again 👍🏻 fixed up

This comment has been minimized.

@composerinteralia composerinteralia force-pushed the fix-multi-regexp-bug-21291 branch from c2a151c to 5a49a0f Compare April 29, 2025 01:15
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 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 disable.

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.
@composerinteralia composerinteralia force-pushed the fix-multi-regexp-bug-21291 branch from 5a49a0f to 30bd755 Compare April 29, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants