Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -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
Expand Down
27 changes: 27 additions & 0 deletions template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading