diff --git a/cmd/helm/create_test.go b/cmd/helm/create_test.go index 88d9c315a..b93029494 100644 --- a/cmd/helm/create_test.go +++ b/cmd/helm/create_test.go @@ -20,6 +20,7 @@ import ( "fmt" "os" "path/filepath" + "regexp" "testing" "helm.sh/helm/v4/internal/test/ensure" @@ -58,6 +59,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 4f59b9f83..c82a217d0 100644 --- a/pkg/chartutil/create.go +++ b/pkg/chartutil/create.go @@ -77,7 +77,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.