From abd33764e8738e9d46b6ec9dc5d7f73f1eeee675 Mon Sep 17 00:00:00 2001 From: Liam White Date: Fri, 16 Feb 2018 10:44:47 +0000 Subject: [PATCH] Fix linting bug with charts containing more than one hyphen --- cmd/helm/lint.go | 6 +++++- cmd/helm/lint_test.go | 19 +++++++++++++----- .../compressedchart-with-hyphens-0.1.0.tgz | Bin 0 -> 548 bytes 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 cmd/helm/testdata/testcharts/compressedchart-with-hyphens-0.1.0.tgz diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index f529f8ce5..29eea1a88 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -149,7 +149,11 @@ func lintChart(path string, vals []byte, namespace string, strict bool) (support return linter, err } - base := strings.Split(filepath.Base(path), "-")[0] + lastHyphenIndex := strings.LastIndex(filepath.Base(path), "-") + if lastHyphenIndex <= 0 { + return linter, fmt.Errorf("unable to parse chart archive %q, missing '-'", filepath.Base(path)) + } + base := filepath.Base(path)[:lastHyphenIndex] chartPath = filepath.Join(tempDir, base) } else { chartPath = path diff --git a/cmd/helm/lint_test.go b/cmd/helm/lint_test.go index e52bdc056..7f045153c 100644 --- a/cmd/helm/lint_test.go +++ b/cmd/helm/lint_test.go @@ -21,11 +21,13 @@ import ( ) var ( - values = []byte{} - namespace = "testNamespace" - strict = false - archivedChartPath = "testdata/testcharts/compressedchart-0.1.0.tgz" - chartDirPath = "testdata/testcharts/decompressedchart/" + values = []byte{} + namespace = "testNamespace" + strict = false + archivedChartPath = "testdata/testcharts/compressedchart-0.1.0.tgz" + archivedChartPathWithHyphens = "testdata/testcharts/compressedchart-with-hyphens-0.1.0.tgz" + invalidArchivedChartPath = "testdata/testcharts/invalidcompressedchart0.1.0.tgz" + chartDirPath = "testdata/testcharts/decompressedchart/" ) func TestLintChart(t *testing.T) { @@ -37,4 +39,11 @@ func TestLintChart(t *testing.T) { t.Errorf("%s", err) } + if _, err := lintChart(archivedChartPathWithHyphens, values, namespace, strict); err != nil { + t.Errorf("%s", err) + } + + if _, err := lintChart(invalidArchivedChartPath, values, namespace, strict); err == nil { + t.Errorf("Expected a chart parsing error") + } } diff --git a/cmd/helm/testdata/testcharts/compressedchart-with-hyphens-0.1.0.tgz b/cmd/helm/testdata/testcharts/compressedchart-with-hyphens-0.1.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..379210a92c1795429d2c4baae389f1e971f26824 GIT binary patch literal 548 zcmV+<0^9u`iwG0|00000|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PL4fi`y^|#dG$jc->rDXjD0A64=|)92WW)wwIoYVoz*QSrU?* zG;H^~7dcDXrjTqgP3fZFMMBsbi zPWu0B_M89nr2n%p#E0nPPIpGV%QZGNX)If*N~tSYQG5|qH0t|nfN!leE_nEwltQJ< z5{(E&Ep_!Aj+6*;9W6i9KdlR0WlY0RR8Xa#gbc6aWCh@%&~0 literal 0 HcmV?d00001