mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-29 13:48:09 -06:00
Merge commit from fork
* Add safe regex matching with timeouts and validation * Remove redundant length check * Remove timeouterror workaround
This commit is contained in:
@@ -206,6 +206,22 @@ class TestMatching(_TestMatchingBase):
|
||||
def test_tach_invalid_regex(self):
|
||||
self._test_matching("[", "MATCH_REGEX", [], ["Don't match this"])
|
||||
|
||||
def test_match_regex_timeout_returns_false(self):
|
||||
tag = Tag.objects.create(
|
||||
name="slow",
|
||||
match=r"(a+)+$",
|
||||
matching_algorithm=Tag.MATCH_REGEX,
|
||||
)
|
||||
document = Document(content=("a" * 5000) + "X")
|
||||
|
||||
with self.assertLogs("paperless.regex", level="WARNING") as cm:
|
||||
self.assertFalse(matching.matches(tag, document))
|
||||
|
||||
self.assertTrue(
|
||||
any("timed out" in message for message in cm.output),
|
||||
f"Expected timeout log, got {cm.output}",
|
||||
)
|
||||
|
||||
def test_match_fuzzy(self):
|
||||
self._test_matching(
|
||||
"Springfield, Miss.",
|
||||
|
||||
Reference in New Issue
Block a user