diff --git a/template/template.go b/template/template.go index fbb28541c1..74063ee5f7 100644 --- a/template/template.go +++ b/template/template.go @@ -463,10 +463,16 @@ func DeepCopyWithTemplate(value any, tmplTextFunc TemplateFunc) (any, error) { if ok == nil { var inlineType any err := yaml.Unmarshal([]byte(parsed), &inlineType) - if err != nil || (inlineType != nil && reflect.TypeOf(inlineType).Kind() == reflect.String) { + if err != nil { // ignore error, thus the string is not an interface return parsed, ok } + if inlineString, isString := inlineType.(string); isString { + return inlineString, ok + } + if strings.TrimSpace(parsed) == "" { + return parsed, ok + } return DeepCopyWithTemplate(inlineType, tmplTextFunc) } return parsed, ok diff --git a/template/template_test.go b/template/template_test.go index 9d481ced2c..fb93a9335c 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -693,6 +693,33 @@ func TestDeepCopyWithTemplate(t *testing.T) { fn: withSuffix, want: "hello-templated", }, + { + title: "quoted numeric string stays string", + input: "hello", + fn: TemplateFunc(func(string) (string, error) { + return "\"123\"", nil + }), + want: "123", + }, + { + title: "quoted numeric string stays string in nested map", + input: map[string]any{ + "customfield_11209": map[string]any{ + "id": "TOKEN", + }, + }, + fn: TemplateFunc(func(s string) (string, error) { + if s == "TOKEN" { + return "\"15129\"", nil + } + return s, nil + }), + want: map[string]any{ + "customfield_11209": map[string]any{ + "id": "15129", + }, + }, + }, { title: "string parsed as YAML map", input: "foo: bar",