Skip to content

fix(parser): reject |not modifier with guidance toward condition negation#103

Merged
mostafa merged 1 commit into
mainfrom
fix/not-modifier-guidance
May 13, 2026
Merged

fix(parser): reject |not modifier with guidance toward condition negation#103
mostafa merged 1 commit into
mainfrom
fix/not-modifier-guidance

Conversation

@mostafa
Copy link
Copy Markdown
Member

@mostafa mostafa commented May 13, 2026

Summary

A common mistranslation from pySigma's docs lands as field|not: value or field|contains|not: value in YAML, and the parser would previously surface it as the generic Unknown modifier 'not' error. Sigma reserves not exclusively for condition expressions; there is no value modifier of that name in pySigma either.

This PR adds a dedicated SigmaParserError::NotIsNotAModifier variant whose message points users at the two correct alternatives:

  • condition: not selection for whole-detection negation.
  • selection and not filter with the inverted predicate moved into a separate detection used as a filter.

The parser short-circuits on mod_str == "not" inside parse_field_spec before falling through to the unknown-modifier path.

Tests

  • test_not_modifier_is_rejected_with_guidance covers both field|not and field|contains|not, asserts the dedicated error variant, and pins the error message wording so the guidance text doesn't drift.

All workspace tests pass; clippy + fmt clean.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --workspace

…gation

A common mistranslation from pySigma's documentation lands as
`field|not: value` or `field|contains|not: value` in the YAML, which the
parser would previously surface as the generic "Unknown modifier 'not'"
error. Sigma reserves `not` exclusively for condition expressions; there
is no value modifier of that name in pySigma either.

Add a dedicated `SigmaParserError::NotIsNotAModifier` variant whose
message points users at the two correct alternatives:

- `condition: not selection` for whole-detection negation.
- `selection and not filter` with the inverted predicate moved into a
  separate detection used as a filter.

The parser now short-circuits on `mod_str == "not"` inside
`parse_field_spec` before falling through to the unknown-modifier path,
so the diagnostic mentions the workaround instead of just naming the
unsupported token.

Tests:
- `test_not_modifier_is_rejected_with_guidance` covers both `field|not`
  and `field|contains|not`, asserts the dedicated error variant, and
  pins the error message wording so the guidance text doesn't drift.
@mostafa mostafa merged commit 9840a4e into main May 13, 2026
18 of 19 checks passed
@mostafa mostafa deleted the fix/not-modifier-guidance branch May 13, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant