Skip to content

Commit

Permalink
Merge pull request #302 from frack113/null-regex
Browse files Browse the repository at this point in the history
Deal with empty string for ignore_case_brackets
  • Loading branch information
thomaspatzke authored Nov 10, 2024
2 parents ad6f3c3 + 21feb6b commit ebbe618
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sigma/processing/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,11 @@ def __post_init__(self):

def apply_string_value(self, field: str, val: SigmaString) -> Optional[SigmaString]:
regex = ""

# empty string can not be convert into a simple regex
if val == "":
return SigmaRegularExpression("")

for sc in val.s: # iterate over all SigmaString components (strings and special chars)
if isinstance(sc, str): # if component is a string
if (
Expand Down
7 changes: 7 additions & 0 deletions tests/test_processing_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,13 @@ def test_regex_transformation_plain_method(dummy_pipeline):
assert detection_item.value[0] == SigmaRegularExpression("\\\\te\\.st.*va.ue")


def test_regex_transformation_empty_string(dummy_pipeline):
detection_item = SigmaDetectionItem("field", [], [SigmaString("")])
transformation = RegexTransformation(method="plain")
transformation.apply_detection_item(detection_item)
assert detection_item.value[0] == SigmaRegularExpression("")


def test_regex_transformation_case_insensitive_bracket_method(dummy_pipeline):
detection_item = SigmaDetectionItem("field", [], [SigmaString("\\tE.sT*val?ue")])
transformation = RegexTransformation(method="ignore_case_brackets")
Expand Down

0 comments on commit ebbe618

Please sign in to comment.