diff --git a/pkg/apis/pipeline/v1beta1/param_types.go b/pkg/apis/pipeline/v1beta1/param_types.go index 068278264fd..c4414f2e15a 100644 --- a/pkg/apis/pipeline/v1beta1/param_types.go +++ b/pkg/apis/pipeline/v1beta1/param_types.go @@ -199,7 +199,7 @@ func (arrayOrString *ArrayOrString) ApplyReplacements(stringReplacements map[str if arrayOrString.Type == ParamTypeString { arrayOrString.StringVal = substitution.ApplyReplacements(arrayOrString.StringVal, stringReplacements) } else { - var newArrayVal []string + newArrayVal := []string{} for _, v := range arrayOrString.ArrayVal { newArrayVal = append(newArrayVal, substitution.ApplyArrayReplacements(v, stringReplacements, arrayReplacements)...) } diff --git a/pkg/apis/pipeline/v1beta1/param_types_test.go b/pkg/apis/pipeline/v1beta1/param_types_test.go index b9dedac0100..d288d28e5c8 100644 --- a/pkg/apis/pipeline/v1beta1/param_types_test.go +++ b/pkg/apis/pipeline/v1beta1/param_types_test.go @@ -200,7 +200,18 @@ func TestArrayOrString_ApplyReplacements(t *testing.T) { }, expectedOutput: v1beta1.NewArrayOrString("firstvalue", "array", "value", "lastvalue", "asdf", "sdfsd"), }, { - name: "empty array replacement", + name: "empty array replacement without extra elements", + args: args{ + // input: v1beta1.NewArrayOrString("$(arraykey)"), + input: &v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeArray, + ArrayVal: []string{"$(arraykey)"}, + }, + arrayReplacements: map[string][]string{"arraykey": {}}, + }, + expectedOutput: &v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{}}, + }, { + name: "empty array replacement with extra elements", args: args{ input: v1beta1.NewArrayOrString("firstvalue", "$(arraykey)", "lastvalue"), stringReplacements: map[string]string{"some": "value", "anotherkey": "value"},