From fc3484f4b32a06619a5cbc948a5c8955048434ed Mon Sep 17 00:00:00 2001 From: Tarun Koyalwar Date: Tue, 9 Jan 2024 21:31:10 +0530 Subject: [PATCH] add logical check before creating result: #4603 --- pkg/protocols/protocols.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/protocols/protocols.go b/pkg/protocols/protocols.go index 1e05080cab..37ca4b8451 100644 --- a/pkg/protocols/protocols.go +++ b/pkg/protocols/protocols.go @@ -215,9 +215,19 @@ type Request interface { type OutputEventCallback func(result *output.InternalWrappedEvent) func MakeDefaultResultEvent(request Request, wrapped *output.InternalWrappedEvent) []*output.ResultEvent { + // Note: operator result is generated if something was succesfull match/extract/dynamic-extract + // but results should not be generated if + // 1. no match was found and some dynamic values were extracted + // 2. if something was extracted (matchers exist but no match was found) if len(wrapped.OperatorsResult.DynamicValues) > 0 && !wrapped.OperatorsResult.Matched { return nil } + // check if something was extracted (except dynamic values) + extracted := len(wrapped.OperatorsResult.Extracts) > 0 || len(wrapped.OperatorsResult.OutputExtracts) > 0 + if extracted && len(wrapped.OperatorsResult.Operators.Matchers) > 0 && !wrapped.OperatorsResult.Matched { + // if extracted and matchers exist but no match was found then don't generate result + return nil + } results := make([]*output.ResultEvent, 0, len(wrapped.OperatorsResult.Matches)+1)