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

automata: fix bug where reverse NFA lacked an unanchored prefix #1170

Merged
merged 1 commit into from Mar 4, 2024

Conversation

BurntSushi
Copy link
Member

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

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 BurntSushi merged commit 9cf4a42 into master Mar 4, 2024
16 checks passed
@BurntSushi BurntSushi deleted the ag/fix-reverse-unanchored-prefix branch March 4, 2024 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Valid prefix search (with ^) goes into dead state
1 participant