Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions intelmq/bots/experts/modify/expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,10 @@ def matches(self, identifier, event, condition):
if name not in event:
return None
if is_re_pattern(rule):
if isinstance(event[name], (int, float)):
match = rule.search(str(event[name]))
if match is None:
return None
else:
matches[name] = match
else:
match = rule.search(event[name])
if match is None:
return None
else:
matches[name] = match
matches[name] = match
else: # rule is boolean, int, float, etc
if event[name] != rule:
return None
Expand Down
16 changes: 16 additions & 0 deletions intelmq/tests/bots/experts/modify/test_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ def test_maximum_matches(self):
del out['classification.identifier']
self.assertMessageEqual(0, out)

def test_modify_regex_without_parentheses_matches_same_as_with_parentheses():
import re
from intelmq.bots.experts.modify.expert import ModifyExpertBot
from intelmq.lib.message import Event

bot = ModifyExpertBot.__new__(ModifyExpertBot)

event = Event()
event.add("extra.test", "12.3")

cond_no_parens = {"extra.test": re.compile(r"^12\.[34]")}
cond_with_parens = {"extra.test": re.compile(r"^(12\.[34])")}

assert bot.matches("no-parens", event, cond_no_parens) is not None
assert bot.matches("with-parens", event, cond_with_parens) is not None


if __name__ == '__main__': # pragma: no cover
unittest.main()