Skip to content

Commit 4894c8d

Browse files
committed
test: cover subject-length cap fail-safe in allowlist pattern matching
1 parent a6cf3fd commit 4894c8d

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_allowlist.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,37 @@ def test_overlong_pattern_rejected(self):
8787
with pytest.raises(ValueError, match="at most"):
8888
datafog.scan("text", engine="regex", allowlist_patterns=["a" * 513])
8989

90+
def test_overlong_entity_text_skips_patterns_but_is_kept(self):
91+
# Fail-safe: an entity too long to pattern-match safely must still
92+
# be reported, never silently suppressed.
93+
from datafog.engine import Entity, _apply_allowlist
94+
95+
long_entity = Entity(
96+
type="EMAIL",
97+
text="a" * 600,
98+
start=0,
99+
end=600,
100+
confidence=1.0,
101+
engine="regex",
102+
)
103+
kept = _apply_allowlist([long_entity], None, [r".*"])
104+
assert kept == [long_entity]
105+
106+
def test_overlong_entity_text_still_matches_exact_allowlist(self):
107+
# The subject-length cap only bounds regex matching; exact string
108+
# comparison is O(n) and still applies.
109+
from datafog.engine import Entity, _apply_allowlist
110+
111+
long_entity = Entity(
112+
type="EMAIL",
113+
text="a" * 600,
114+
start=0,
115+
end=600,
116+
confidence=1.0,
117+
engine="regex",
118+
)
119+
assert _apply_allowlist([long_entity], ["a" * 600], None) == []
120+
90121
def test_benign_quantified_group_still_allowed(self):
91122
result = datafog.scan(
92123
f"mail {EMAIL}",

0 commit comments

Comments
 (0)