From b73bd29133cfcf2e75fdd1dad13d3de3976620b6 Mon Sep 17 00:00:00 2001 From: Andreas Karis Date: Mon, 31 May 2021 16:41:55 +0200 Subject: [PATCH] fix(helm): Quote chart names in helm create Quote chart names when creating charts with helm create. Fixes #9650 Signed-off-by: Andreas Karis --- cmd/helm/create_test.go | 15 +++++++++++++++ pkg/chartutil/create.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/helm/create_test.go b/cmd/helm/create_test.go index 1db6bed52..335f06089 100644 --- a/cmd/helm/create_test.go +++ b/cmd/helm/create_test.go @@ -21,6 +21,7 @@ import ( "io/ioutil" "os" "path/filepath" + "regexp" "testing" "helm.sh/helm/v3/internal/test/ensure" @@ -59,6 +60,20 @@ func TestCreateCmd(t *testing.T) { if c.Metadata.APIVersion != chart.APIVersionV2 { t.Errorf("Wrong API version: %q", c.Metadata.APIVersion) } + + // Test that the name in Chart.yaml is quoted + chartPath := cname + "/Chart.yaml" + fileContent, err := ioutil.ReadFile(chartPath) + if err != nil { + t.Errorf("Got error when reading Chart.yaml at path %q: %q", chartPath, err) + } + m, err := regexp.Match("\nname: \""+cname+"\"\n", fileContent) + if err != nil { + t.Errorf("Could not apply regex for file %q", chartPath) + } + if !m { + t.Errorf("Could not find quoted name in %q", chartPath) + } } func TestCreateStarterCmd(t *testing.T) { diff --git a/pkg/chartutil/create.go b/pkg/chartutil/create.go index ca79e7ab2..550163508 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -78,7 +78,7 @@ const maxChartNameLength = 250 const sep = string(filepath.Separator) const defaultChartfile = `apiVersion: v2 -name: %s +name: "%s" description: A Helm chart for Kubernetes # A chart can be either an 'application' or a 'library' chart.