From ece46c1d3a44e5f90cca0cbb96ae302dc47885cb Mon Sep 17 00:00:00 2001 From: d-d-up Date: Tue, 9 Aug 2022 14:12:26 +0800 Subject: [PATCH] fix special string in the filename Signed-off-by: d-d-up --- pkg/cli/values/options.go | 5 ++++- pkg/cli/values/options_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/cli/values/options.go b/pkg/cli/values/options.go index a28ffa99fd5..1329fa0fcb0 100644 --- a/pkg/cli/values/options.go +++ b/pkg/cli/values/options.go @@ -112,7 +112,10 @@ func readFile(filePath string, p getter.Providers) ([]byte, error) { if strings.TrimSpace(filePath) == "-" { return ioutil.ReadAll(os.Stdin) } - u, _ := url.Parse(filePath) + u, err := url.Parse(filePath) + if err != nil { + return nil, err + } // FIXME: maybe someone handle other protocols like ftp. g, err := p.ByScheme(u.Scheme) diff --git a/pkg/cli/values/options_test.go b/pkg/cli/values/options_test.go index d988274bfaf..54124c0fa42 100644 --- a/pkg/cli/values/options_test.go +++ b/pkg/cli/values/options_test.go @@ -19,6 +19,8 @@ package values import ( "reflect" "testing" + + "helm.sh/helm/v3/pkg/getter" ) func TestMergeValues(t *testing.T) { @@ -75,3 +77,12 @@ func TestMergeValues(t *testing.T) { t.Errorf("Expected a map with different keys to merge properly with another map. Expected: %v, got %v", expectedMap, testMap) } } + +func TestReadFile(t *testing.T) { + var p getter.Providers + filePath := "%a.txt" + _, err := readFile(filePath, p) + if err == nil { + t.Errorf("Expected error when has special strings") + } +}