Browse Source

fix: unused delimiter settings (#4807)

Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
Gergely Brautigam 11 months ago
parent
commit
af8c214451
2 changed files with 7 additions and 1 deletions
  1. 1 1
      pkg/template/v2/template.go
  2. 6 0
      pkg/template/v2/template_test.go

+ 1 - 1
pkg/template/v2/template.go

@@ -164,7 +164,7 @@ func execute(k, val string, data map[string][]byte) ([]byte, error) {
 	t, err := tpl.New(k).
 	t, err := tpl.New(k).
 		Option("missingkey=error").
 		Option("missingkey=error").
 		Funcs(tplFuncs).
 		Funcs(tplFuncs).
-		Delims("{{", "}}").
+		Delims(leftDelim, rightDelim).
 		Parse(val)
 		Parse(val)
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf(errParse, k, err)
 		return nil, fmt.Errorf(errParse, k, err)

+ 6 - 0
pkg/template/v2/template_test.go

@@ -515,12 +515,18 @@ func TestExecute(t *testing.T) {
 				StringData: make(map[string]string),
 				StringData: make(map[string]string),
 				ObjectMeta: v1.ObjectMeta{Labels: make(map[string]string), Annotations: make(map[string]string)},
 				ObjectMeta: v1.ObjectMeta{Labels: make(map[string]string), Annotations: make(map[string]string)},
 			}
 			}
+			oldLeftDelim := leftDelim
+			oldRightDelim := rightDelim
 			if row.leftDelimiter != "" {
 			if row.leftDelimiter != "" {
 				leftDelim = row.leftDelimiter
 				leftDelim = row.leftDelimiter
 			}
 			}
 			if row.rightDelimiter != "" {
 			if row.rightDelimiter != "" {
 				rightDelim = row.rightDelimiter
 				rightDelim = row.rightDelimiter
 			}
 			}
+			defer func() {
+				leftDelim = oldLeftDelim
+				rightDelim = oldRightDelim
+			}()
 			err := Execute(row.tpl, row.data, esapi.TemplateScopeValues, esapi.TemplateTargetData, sec)
 			err := Execute(row.tpl, row.data, esapi.TemplateScopeValues, esapi.TemplateTargetData, sec)
 			if !ErrorContains(err, row.expErr) {
 			if !ErrorContains(err, row.expErr) {
 				t.Errorf("unexpected error: %s, expected: %s", err, row.expErr)
 				t.Errorf("unexpected error: %s, expected: %s", err, row.expErr)