Conditions - Fixing "Does NOT contain" condition (#3279 / #3272 )

pull/3271/merge
dgtlmoon 2025-06-24 16:29:10 +02:00 zatwierdzone przez GitHub
rodzic a7214db9c3
commit 58e2a41c95
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 7 dodań i 3 usunięć

Wyświetl plik

@ -16,7 +16,6 @@ operator_choices = [
("==", "Equals"),
("!=", "Not Equals"),
("in", "Contains"),
("!in", "Does Not Contain"),
]
# Fields available in the rules

Wyświetl plik

@ -21,17 +21,21 @@ def register_operators():
def length_max(_, text, strlen):
return len(text) <= int(strlen)
# Custom function for case-insensitive regex matching
# Custom function for case-insensitive regex matching
def contains_regex(_, text, pattern):
"""Returns True if `text` contains `pattern` (case-insensitive regex match)."""
return bool(re.search(pattern, str(text), re.IGNORECASE))
# Custom function for NOT matching case-insensitive regex
# Custom function for NOT matching case-insensitive regex
def not_contains_regex(_, text, pattern):
"""Returns True if `text` does NOT contain `pattern` (case-insensitive regex match)."""
return not bool(re.search(pattern, str(text), re.IGNORECASE))
def not_contains(_, text, pattern):
return not pattern in text
return {
"!in": not_contains,
"!contains_regex": not_contains_regex,
"contains_regex": contains_regex,
"ends_with": ends_with,
@ -43,6 +47,7 @@ def register_operators():
@hookimpl
def register_operator_choices():
return [
("!in", "Does NOT Contain"),
("starts_with", "Text Starts With"),
("ends_with", "Text Ends With"),
("length_min", "Length minimum"),