From 8331495937eb50317b278b1d02905bbeae0e8736 Mon Sep 17 00:00:00 2001 From: Calum Murray Date: Thu, 28 Sep 2023 15:53:03 -0400 Subject: [PATCH] Make closer to suffix filter Signed-off-by: Calum Murray --- pkg/eventfilter/subscriptionsapi/prefix_filter.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/eventfilter/subscriptionsapi/prefix_filter.go b/pkg/eventfilter/subscriptionsapi/prefix_filter.go index 8a95e28124f..fc19911decf 100644 --- a/pkg/eventfilter/subscriptionsapi/prefix_filter.go +++ b/pkg/eventfilter/subscriptionsapi/prefix_filter.go @@ -50,13 +50,9 @@ func (filter *prefixFilter) Filter(ctx context.Context, event cloudevents.Event) if filter == nil { return eventfilter.NoFilter } - result := eventfilter.NoFilter logger := logging.FromContext(ctx) logger.Debugw("Performing a prefix match ", zap.Any("filters", filter.filters), zap.Any("event", event)) for k, v := range filter.filters { - if k == "" || v == "" { - continue - } value, ok := attributes.LookupAttribute(event, k) if !ok { logger.Debugw("Couldn't find attribute in event. Prefix match failed.", zap.String("attribute", k), zap.String("prefix", v), @@ -67,13 +63,11 @@ func (filter *prefixFilter) Filter(ctx context.Context, event cloudevents.Event) if s, ok = value.(string); !ok { s = fmt.Sprintf("%v", value) } - if strings.HasPrefix(s, v) { - result = eventfilter.PassFilter - } else { + if !strings.HasPrefix(s, v) { return eventfilter.FailFilter } } - return result + return eventfilter.PassFilter } func (filter *prefixFilter) Cleanup() {}