Skip to content

Commit 7dfe056

Browse files
Add alignment checking for subqueries
1 parent c6f1c90 commit 7dfe056

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

detection_rules/rule_validators.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,17 @@ def remote_validate_rule( # noqa: PLR0913
929929
return response
930930

931931

932-
def extract_error_field(source: str, exc: eql.EqlParseError | kql.KqlParseError) -> str | None:
932+
def extract_error_field(source: str, exc: eql.EqlParseError | kql.KqlParseError, max_attempts: int = 10) -> str | None:
933933
"""Extract the field name from an EQL or KQL parse error."""
934934
lines = source.splitlines()
935935
mod = -1 if exc.line == len(lines) else 0 # type: ignore[reportUnknownMemberType]
936936
line = lines[exc.line + mod] # type: ignore[reportUnknownMemberType]
937-
start = exc.column # type: ignore[reportUnknownMemberType]
937+
start: int = exc.column # type: ignore[reportUnknownMemberType]
938+
# Handle cases where subqueries cause column alignment to be off
939+
for _ in range(max_attempts):
940+
if line[start - 1] != " ":
941+
start -= 1
942+
else:
943+
break
938944
stop = start + len(exc.caret.strip()) # type: ignore[reportUnknownVariableType]
939945
return re.sub(r"^\W+|\W+$", "", line[start:stop]) # type: ignore[reportUnknownArgumentType]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "detection_rules"
3-
version = "1.5.5"
3+
version = "1.5.6"
44
description = "Detection Rules is the home for rules used by Elastic Security. This repository is used for the development, maintenance, testing, validation, and release of rules for Elastic Security’s Detection Engine."
55
readme = "README.md"
66
requires-python = ">=3.12"

0 commit comments

Comments
 (0)