Skip to content

Commit

Permalink
misc: fix invalid escape warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonish committed Oct 26, 2023
1 parent 005e1e6 commit 27595e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions idstools/scripts/rulecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def parse(cls, buf):
pattern = re.compile(a)

# Convert Oinkmaster backticks to Python.
b = re.sub("\$\{(\d+)\}", "\\\\\\1", b)
b = re.sub(r"\$\{(\d+)\}", "\\\\\\1", b)

return cls(matcher, pattern, b)

Expand All @@ -244,7 +244,7 @@ def match(self, rule):
return self.matcher.match(rule)

def filter(self, rule):
drop_rule = idstools.rule.parse(re.sub("^\w+", "drop", rule.raw))
drop_rule = idstools.rule.parse(re.sub(r"^\w+", "drop", rule.raw))
drop_rule.enabled = rule.enabled
return drop_rule

Expand Down Expand Up @@ -592,9 +592,9 @@ def resolve_flowbits(rulemap, disabled_rules):
class ThresholdProcessor:

patterns = [
re.compile("\s+(re:\"(.*)\")"),
re.compile("\s+(re:(.*?)),.*"),
re.compile("\s+(re:(.*))"),
re.compile(r"\s+(re:\"(.*)\")"),
re.compile(r"\s+(re:(.*?)),.*"),
re.compile(r"\s+(re:(.*))"),
]

def extract_regex(self, buf):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rulecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class ModifyRuleFilterTestCase(unittest.TestCase):

def test_id_match(self):
rule0 = idstools.rule.parse(self.rule_string)
line = '2020757 "\|0d 0a\|" "|ff ff|"'
line = r'2020757 "\|0d 0a\|" "|ff ff|"'
rule_filter = rulecat.ModifyRuleFilter.parse(line)
self.assertTrue(rule_filter != None)
self.assertTrue(rule_filter.match(rule0))
Expand All @@ -181,7 +181,7 @@ def test_id_match(self):

def test_re_match(self):
rule0 = idstools.rule.parse(self.rule_string)
line = 're:classtype:trojan-activity "\|0d 0a\|" "|ff ff|"'
line = r're:classtype:trojan-activity "\|0d 0a\|" "|ff ff|"'
rule_filter = rulecat.ModifyRuleFilter.parse(line)
self.assertTrue(rule_filter != None)
self.assertTrue(rule_filter.match(rule0))
Expand Down

0 comments on commit 27595e4

Please sign in to comment.