From b27426a604df140e52a5bb1d0b77cfa706c21dce Mon Sep 17 00:00:00 2001 From: liujian <54946465+redscholar@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:57:49 +0800 Subject: [PATCH] fix: error parse when (#2505) Signed-off-by: joyceliu Co-authored-by: joyceliu --- api/project/v1/conditional.go | 2 +- pkg/converter/tmpl/template.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/project/v1/conditional.go b/api/project/v1/conditional.go index 638c1429..6ef9c589 100644 --- a/api/project/v1/conditional.go +++ b/api/project/v1/conditional.go @@ -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: diff --git a/pkg/converter/tmpl/template.go b/pkg/converter/tmpl/template.go index 7f22ed0b..d6b8926f 100644 --- a/pkg/converter/tmpl/template.go +++ b/pkg/converter/tmpl/template.go @@ -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.