Skip to content

Commit

Permalink
Fix the issue with empty array replacement
Browse files Browse the repository at this point in the history
Prior to this change, if there is only one element in an array that is
a reference to an empty array, the original array becomes nil after
replacement, but it should be an empty array instead of nil.

Fixes #5149
  • Loading branch information
chuangw6 authored and tekton-robot committed Jul 18, 2022
1 parent 10ecefb commit 94055d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/param_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (arrayOrString ArrayOrString) MarshalJSON() ([]byte, error) {
func (arrayOrString *ArrayOrString) ApplyReplacements(stringReplacements map[string]string, arrayReplacements map[string][]string, objectReplacements map[string]map[string]string) {
switch arrayOrString.Type {
case ParamTypeArray:
var newArrayVal []string
newArrayVal := []string{}
for _, v := range arrayOrString.ArrayVal {
newArrayVal = append(newArrayVal, substitution.ApplyArrayReplacements(v, stringReplacements, arrayReplacements)...)
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/apis/pipeline/v1beta1/param_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,14 @@ 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)"),
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"},
Expand Down

0 comments on commit 94055d9

Please sign in to comment.