-
Notifications
You must be signed in to change notification settings - Fork 446
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
Valid prefix search (with ^) goes into dead state #1169
Labels
Comments
acarl005
changed the title
Including a ^ forces the entire line to match
Valid prefix search (with ^) goes into dead state
Mar 4, 2024
BurntSushi
added a commit
that referenced
this issue
Mar 4, 2024
Previously, when compiling a Thompson NFA, we were omitting an unanchored prefix when the HIR contained a `^` in its prefix. We did this because unanchored prefix in that case would never match because of the requirement imposed by `^`. The problem with that is it's incorrect when compiling a reverse automaton. For example, in the case of building a reverse NFA for `^Qu`, we should sitll include an unanchored prefix because the `^` in that case has no conflict with it. It would be like if we omitted an unanchored prefix for `Qu$` in a forward NFA, which is obviously wrong. The fix here is pretty simple: in the reverse case, check for `$` in the suffix of the HIR rather than a `^` in the prefix. Fixes #1169
BurntSushi
added a commit
that referenced
this issue
Mar 4, 2024
Previously, when compiling a Thompson NFA, we were omitting an unanchored prefix when the HIR contained a `^` in its prefix. We did this because unanchored prefix in that case would never match because of the requirement imposed by `^`. The problem with that is it's incorrect when compiling a reverse automaton. For example, in the case of building a reverse NFA for `^Qu`, we should sitll include an unanchored prefix because the `^` in that case has no conflict with it. It would be like if we omitted an unanchored prefix for `Qu$` in a forward NFA, which is obviously wrong. The fix here is pretty simple: in the reverse case, check for `$` in the suffix of the HIR rather than a `^` in the prefix. Fixes #1169
This is fixed in |
Thank you for the nice repro. :) |
Thanks for the quick fix! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of regex are you using?
regex-automata = "0.4.5"
Describe the bug at a high level.
I'm trying to do a prefix search by adding a
^
at the beginning of my pattern. I'm searching right-to-left, but the dfa is failing to find a match and entering the "dead" state.What are the steps to reproduce the behavior?
What is the actual behavior?
What is the expected behavior?
I expect the program to run through to the end, finding a match and passing the assertion, as the pattern
^Qu
should match the string "Quartz".If I remove the
^
from the pattern, this program behaves as expected.The text was updated successfully, but these errors were encountered: