From 1d9cd061b146d468b2575d6824e0963979991510 Mon Sep 17 00:00:00 2001 From: Simon Behar Date: Mon, 10 Jun 2019 15:41:34 -0700 Subject: [PATCH] Fixes non-escaped comma bug on Helm command arguments (#1720) --- util/helm/helm.go | 9 +++++++++ util/helm/helm_test.go | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/util/helm/helm.go b/util/helm/helm.go index d387c8324fa80..ccc6526ef3f78 100644 --- a/util/helm/helm.go +++ b/util/helm/helm.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path" + "regexp" "sort" "strings" @@ -210,6 +211,7 @@ func (h *helm) GetParameters(valuesFiles []string) ([]*argoappv1.HelmParameter, } func (h *helm) helmCmd(args ...string) (string, error) { + cleanHelmParameters(args) return h.helmCmdExt(args, func(s string) string { return s }) @@ -248,3 +250,10 @@ func flatVals(input map[string]interface{}, output map[string]string, prefixes . } } } + +func cleanHelmParameters(params []string) { + re := regexp.MustCompile(`([^\\]),`) + for i, param := range params { + params[i] = re.ReplaceAllString(param, `$1\,`) + } +} diff --git a/util/helm/helm_test.go b/util/helm/helm_test.go index 56b9fe26d1859..2657730d4c1d3 100644 --- a/util/helm/helm_test.go +++ b/util/helm/helm_test.go @@ -159,3 +159,22 @@ func TestHelmTemplateReleaseName(t *testing.T) { } } } + +func TestHelmArgCleaner(t *testing.T) { + cleanArgs := []string{`--these-args`, `are-clean`, `--foo`, `bar`} + argsToBeCleaned := make([]string, len(cleanArgs)) + copy(argsToBeCleaned, cleanArgs) + + cleanHelmParameters(argsToBeCleaned) + assert.Equal(t, cleanArgs, argsToBeCleaned) + + dirtyArgs := []string{`--these-args`, `are-not, clean`, `--foo`, `b\,a,r`} + argsToBeCleaned = make([]string, len(dirtyArgs)) + copy(argsToBeCleaned, dirtyArgs) + + cleanHelmParameters(argsToBeCleaned) + assert.NotEqual(t, cleanArgs, argsToBeCleaned) + assert.Contains(t, argsToBeCleaned, `are-not\, clean`) + assert.Contains(t, argsToBeCleaned, `b\,a\,r`) + +}