From 473ad66ddb67bc649b591c43fbc48056142e9903 Mon Sep 17 00:00:00 2001 From: rvandernoort Date: Tue, 22 Mar 2022 11:49:25 +0100 Subject: [PATCH] Use bool var to indicate negation instead of splitting operation again Signed-off-by: rvandernoort --- libimage/filters.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libimage/filters.go b/libimage/filters.go index 6395de3d5..f9f73f527 100644 --- a/libimage/filters.go +++ b/libimage/filters.go @@ -95,8 +95,11 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp for _, f := range options.Filters { var key, value string var filter filterFunc + negate := false split := strings.SplitN(f, "!=", 2) - if len(split) != 2 { + if len(split) == 2 { + negate = true + } else { split = strings.SplitN(f, "=", 2) if len(split) != 2 { return nil, errors.Errorf("invalid image filter %q: must be in the format %q", f, "filter=value or filter!=value") @@ -185,7 +188,7 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp default: return nil, errors.Errorf("unsupported image filter %q", key) } - if len(strings.SplitN(f, "!=", 2)) == 2 { + if negate { filter = negateFilter(filter) } filters[key] = append(filters[key], filter)