Skip to content

Make AllMatches/AllPotentials consistent with FirstMatch on misuse - #656

Open
afonsojanu wants to merge 1 commit into
google:mainfrom
afonsojanu:fix/allmatches-allpotentials-compiled-check
Open

Make AllMatches/AllPotentials consistent with FirstMatch on misuse#656
afonsojanu wants to merge 1 commit into
google:mainfrom
afonsojanu:fix/allmatches-allpotentials-compiled-check

Conversation

@afonsojanu

Copy link
Copy Markdown

FirstMatch() already refuses to run (ABSL_LOG(DFATAL), so it aborts in debug builds) when a FilteredRE2 has patterns added via Add() but Compile() was never called. AllMatches() and AllPotentials() silently skip that same check, so the same misuse that FirstMatch catches goes unnoticed through the other two entry points, similar in spirit to the older Filter.Match() issue that was fixed for the Python bindings (#484).

I left the empty-pattern-set case alone (calling Compile() before any Add()), since that's an existing, intentionally-supported no-op path the EmptyTest test already relies on - the new check only fires when re2_vec_ is non-empty but compiled_ is still false.

Added two death tests (AllMatchesBeforeCompileDies, AllPotentialsBeforeCompileDies) that I confirmed fail against the current code (the calls don't die when they should) and pass once the check is in place. Ran the full non-exhaustive CTest suite before and after; everything else stayed green.

I don't have a completed CLA on file yet, so let me know if that's needed before this can be reviewed.

FirstMatch() already refuses to run (in debug builds) when called on a
FilteredRE2 that has patterns added but Compile() was never called.
AllMatches() and AllPotentials() skipped that same check, so the same
kind of caller mistake that FirstMatch would catch immediately passed
through unnoticed on the other two entry points instead.

The empty-pattern-set case (Compile() called before any Add()) is left
alone since that's an existing, intentionally-supported no-op path
already covered by the EmptyTest test.

Added two death tests that fail on the current code (the calls don't
die when they should) and pass once the check is added.
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.

1 participant