Repository navigation
Conversation
PatternRecognizer.analyze() forwards the caller's regex_flags, but the fallback used a truthiness check, so an explicit 0 (the documented per-request override meaning no flags) was replaced by the recognizer's global flags. A caller could not disable e.g. IGNORECASE for one request. Only None now falls back to the default. Fixes data-privacy-stack#2543
This branch has not been deployed
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.
Summary
PatternRecognizer.analyze()acceptsregex_flagsas a per-request override, but an explicit0(no flags) is silently replaced by the recognizer'sglobal_regex_flagsbecause the fallback uses a truthiness check.Reproduction from the issue: with
global_regex_flags=re.IGNORECASE,analyze("ABC", ["X"], regex_flags=0)still matches a lowercase pattern. There is no way to disableIGNORECASEfor a single request.Behavior change
regex_flags=0now wins over the recognizer default, as documented.Nonestill falls back toglobal_regex_flags, so existing callers that omit the parameter are unaffected.Root cause
flags = flags if flags else self.global_regex_flagstreats0as missing. Changed to anis not Nonecheck.Tests
New test
test_analyze_with_explicit_zero_regex_flags_overrides_globalmirroring the existingtest_pattern_recognizer_analyze_with_custom_regex_flagsfrom the opposite direction: defaultIGNORECASEmatches uppercase text, explicitregex_flags=0does not.Red-green verified: the test fails on unpatched
mainand passes with the fix. Fulltest_pattern_recognizer.py: 46 passed.Security and accuracy impact
No accuracy reduction: detections are unchanged for every caller that does not pass
regex_flags=0explicitly (previously impossible to use meaningfully). No PII logging added.Fixes #2543