From ad166c7f0d223a119f3843b58dc4f8adfab27b4d Mon Sep 17 00:00:00 2001 From: PatDyn <37243484+PatDyn@users.noreply.github.com> Date: Thu, 9 May 2024 14:21:36 +0200 Subject: [PATCH] Sanitize csv strings (#258) * Support spaces before/after commas when passing list of Kinds --- pkg/config/config.go | 1 + pkg/config/config_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index 79447eb..b7df0f4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -63,6 +63,7 @@ func splitCSV(csvStr string) map[string]struct{} { valuesMap := map[string]struct{}{} for _, kind := range splitValues { + kind = strings.TrimSpace(kind) if len(kind) > 0 { valuesMap[kind] = struct{}{} } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 9a184d5..22dbbe1 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -95,6 +95,30 @@ func TestFromFlags(t *testing.T) { RejectKinds: map[string]struct{}{}, }, }, + { + []string{"-skip", "a, b, c"}, + Config{ + Files: []string{}, + KubernetesVersion: "master", + NumberOfWorkers: 4, + OutputFormat: "text", + SchemaLocations: nil, + SkipKinds: map[string]struct{}{"a": {}, "b": {}, "c": {}}, + RejectKinds: map[string]struct{}{}, + }, + }, + { + []string{"-skip", "a,b, c"}, + Config{ + Files: []string{}, + KubernetesVersion: "master", + NumberOfWorkers: 4, + OutputFormat: "text", + SchemaLocations: nil, + SkipKinds: map[string]struct{}{"a": {}, "b": {}, "c": {}}, + RejectKinds: map[string]struct{}{}, + }, + }, { []string{"-summary", "-verbose", "file1", "file2"}, Config{