fix: error parse when (#2505)

Signed-off-by: joyceliu <joyceliu@yunify.com>
Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
liujian 2025-03-12 16:57:49 +08:00 committed by GitHub
parent 93addfb88e
commit b27426a604
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -47,7 +47,7 @@ func (w *When) UnmarshalYAML(node *yaml.Node) error {
}
for i, v := range w.Data {
if !IsTmplSyntax(v) {
w.Data[i] = ParseTmplSyntax(node.Value)
w.Data[i] = ParseTmplSyntax(v)
}
}
default:

View File

@ -36,7 +36,7 @@ import (
func ParseFunc[C ~map[string]any, Output any](ctx C, input string, f func([]byte) Output) (Output, error) {
// If input doesn't contain template syntax, return directly
if !kkprojectv1.IsTmplSyntax(input) {
return f([]byte(input)), nil
return f(bytes.Trim([]byte(input), "\r\n")), nil
}
// Parse the template string
tl, err := internal.Template.Parse(input)
@ -52,7 +52,7 @@ func ParseFunc[C ~map[string]any, Output any](ctx C, input string, f func([]byte
klog.V(6).InfoS(" parse template succeed", "result", result.String())
// Apply parse function to result and return
return f(result.Bytes()), nil
return f(bytes.Trim(result.Bytes(), "\r\n")), nil
}
// Parse is a helper function that wraps ParseFunc to directly return bytes.