Make AllMatches/AllPotentials consistent with FirstMatch on misuse - #656
Open
afonsojanu wants to merge 1 commit into
Open
Make AllMatches/AllPotentials consistent with FirstMatch on misuse#656afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.