Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,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
}
Comment thread
holger-waschke marked this conversation as resolved.
// inlineType holds structured data decoded from the rendered string.
// This is already final data, so only normalize it into JSON-compatible
// types. It must not be passed back through DeepCopyWithTemplate, because
Expand Down
27 changes: 27 additions & 0 deletions template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,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",
Expand Down
Loading