Skip to content

Commit fdd5cd4

Browse files
Copilotthomaspatzke
andcommitted
Move field_eq_val regex to class-level constant to avoid recompilation
Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
1 parent 79260d1 commit fdd5cd4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sigma/backends/splunk/splunk.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ class SplunkBackend(TextQueryBackend):
199199
deferred_separator: ClassVar[str] = "\n| "
200200
deferred_only_query: ClassVar[str] = "*"
201201

202+
# Pattern matching a leading field=value term in a query string.
203+
_field_eq_val_re: ClassVar[Pattern] = re.compile(
204+
r'([\w.]+)(?:="[^"]*"|=[^\s")]+)\s*'
205+
)
206+
202207
# Correlations
203208
correlation_methods: ClassVar[Dict[str, str]] = {
204209
"stats": "Correlation using stats command (more efficient, static time window)",
@@ -356,11 +361,8 @@ def finish_query(
356361
# inside the trailing "| search" clause.
357362
prefix_parts = []
358363
pos = 0
359-
field_eq_val_re = re.compile(
360-
r'([\w.]+)(?:="[^"]*"|=[^\s")]+)\s*'
361-
)
362364
while pos < len(query):
363-
m = field_eq_val_re.match(query, pos)
365+
m = self._field_eq_val_re.match(query, pos)
364366
if m and m.group(1) not in deferred_condition_fields:
365367
prefix_parts.append(m.group().strip())
366368
pos = m.end()

0 commit comments

Comments
 (0)