Skip to content

Commit

Permalink
fix: ApplicationSet Controller crashes when tag is not closed; panic:…
Browse files Browse the repository at this point in the history
… Cannot find end tag="}}"(#14227) (#14651)

* ApplicationSet bug fix

Signed-off-by: schakrad <[email protected]>

* Update applicationset/utils/utils_test.go

Signed-off-by: Michael Crenshaw <[email protected]>

* oops

Signed-off-by: Michael Crenshaw <[email protected]>

---------

Signed-off-by: schakrad <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
  • Loading branch information
schakrad and crenshaw-dev authored Jul 23, 2023
1 parent 2fa12c8 commit fba4aa1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion applicationset/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ func (r *Render) Replace(tmpl string, replaceMap map[string]interface{}, useGoTe
return tmpl, nil
}

fstTmpl := fasttemplate.New(tmpl, "{{", "}}")
fstTmpl, err := fasttemplate.NewTemplate(tmpl, "{{", "}}")
if err != nil {
return "", fmt.Errorf("invalid template: %w", err)
}
replacedTmpl := fstTmpl.ExecuteFuncString(func(w io.Writer, tag string) (int, error) {
trimmedTag := strings.TrimSpace(tag)
replacement, ok := replaceMap[trimmedTag].(string)
Expand Down
8 changes: 8 additions & 0 deletions applicationset/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,14 @@ func TestRenderTemplateKeys(t *testing.T) {
})
}

func Test_Render_Replace_no_panic_on_missing_closing_brace(t *testing.T) {
r := &Render{}
assert.NotPanics(t, func() {
_, err := r.Replace("{{properly.closed}} {{improperly.closed}", nil, false, []string{})
assert.Error(t, err)
})
}

func TestRenderTemplateParamsFinalizers(t *testing.T) {

emptyApplication := &argoappsv1.Application{
Expand Down

0 comments on commit fba4aa1

Please sign in to comment.