Skip to content

Commit

Permalink
Fixes non-escaped comma bug on Helm command arguments (#1720)
Browse files Browse the repository at this point in the history
  • Loading branch information
simster7 authored and alexec committed Jun 10, 2019
1 parent 65cceaf commit 1d9cd06
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions util/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path"
"regexp"
"sort"
"strings"

Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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\,`)
}
}
19 changes: 19 additions & 0 deletions util/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

}

0 comments on commit 1d9cd06

Please sign in to comment.