From 54d8d872b3d5f88aa6db77a6c39b2a0352b38a94 Mon Sep 17 00:00:00 2001 From: Fabian von Feilitzsch Date: Thu, 10 Aug 2023 16:08:22 -0400 Subject: [PATCH] :bug: If all conditions are filtered out, don't add the rule (#291) Closes #289 Signed-off-by: Fabian von Feilitzsch --- parser/rule_parser.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/parser/rule_parser.go b/parser/rule_parser.go index e61ef0e2..4d56abad 100644 --- a/parser/rule_parser.go +++ b/parser/rule_parser.go @@ -610,6 +610,11 @@ func (r *RuleParser) getConditions(conditionsInterface []interface{}) ([]engine. if err != nil { return nil, nil, err } + // There was no error so the conditions have all been filtered + // Return early to prevent constructing an empty rule + if len(conds) == 0 && len(conds) != len(iConditions) { + return []engine.ConditionEntry{}, nil, nil + } ce = engine.ConditionEntry{ From: from, As: as, @@ -631,6 +636,11 @@ func (r *RuleParser) getConditions(conditionsInterface []interface{}) ([]engine. if err != nil { return nil, nil, err } + // There was no error so the conditions have all been filtered + // Return early to prevent constructing an empty rule + if len(conds) == 0 && len(conds) != len(iConditions) { + return []engine.ConditionEntry{}, nil, nil + } ce = engine.ConditionEntry{ From: from, As: as,