Skip to content
Merged
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
7 changes: 7 additions & 0 deletions sigma/backends/sqlite/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from sigma.types import (
SigmaCompareExpression,
SigmaRegularExpression,
SigmaString,
SpecialChars,
SigmaCIDRExpression,
Expand Down Expand Up @@ -477,6 +478,12 @@ def convert_value_str(
else:
return converted

def convert_value_re(
self, r: SigmaRegularExpression, state: ConversionState
) -> str:
# Doubling single quotes is mandatory: the regex is embedded in a '...' SQL string literal.
return super().convert_value_re(r, state).replace("'", "''")

def convert_condition_field_eq_val_str(
self, cond: ConditionFieldEqualsValueExpression, state: ConversionState
) -> Union[str, DeferredQueryExpression]:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_backend_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@ def test_sqlite_regex_query(sqlite_backend: sqliteBackend):
)


def test_sqlite_regex_query_single_quote(sqlite_backend: sqliteBackend):
assert (
sqlite_backend.convert(
SigmaCollection.from_yaml(
"""
title: Test
status: test
logsource:
category: test_category
product: test_product
detection:
sel:
fieldA|re: it's.exe
condition: sel
"""
)
)
== ["SELECT * FROM <TABLE_NAME> WHERE fieldA REGEXP 'it''s.exe'"]
)


def test_sqlite_cidr_query(sqlite_backend: sqliteBackend):
assert (
sqlite_backend.convert(
Expand Down
Loading