From 42f37b4e98e6f9621af4f1da40e831525f65fc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 18 Oct 2024 10:30:36 +0200 Subject: [PATCH] tpl/transform: Don't fail on "no data to transform" Fixes #12964 --- tpl/transform/unmarshal.go | 3 ++- tpl/transform/unmarshal_test.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tpl/transform/unmarshal.go b/tpl/transform/unmarshal.go index 898085661cd..0068947f6d5 100644 --- a/tpl/transform/unmarshal.go +++ b/tpl/transform/unmarshal.go @@ -112,9 +112,10 @@ func (ns *Namespace) Unmarshal(args ...any) (any, error) { if err != nil { return nil, fmt.Errorf("type %T not supported", data) } + dataStr = strings.TrimSpace(dataStr) if dataStr == "" { - return nil, errors.New("no data to transform") + return nil, nil } key := hashing.MD5FromStringHexEncoded(dataStr) diff --git a/tpl/transform/unmarshal_test.go b/tpl/transform/unmarshal_test.go index 1b976c449ad..d65f05fd42e 100644 --- a/tpl/transform/unmarshal_test.go +++ b/tpl/transform/unmarshal_test.go @@ -139,6 +139,8 @@ func TestUnmarshal(t *testing.T) { a;b;c`, mime: media.Builtin.CSVType}, map[string]any{"DElimiter": ";", "Comment": "%"}, func(r [][]string) { b.Assert([][]string{{"a", "b", "c"}}, qt.DeepEquals, r) }}, + {``, nil, nil}, + {` `, nil, nil}, // errors {"thisisnotavaliddataformat", nil, false}, {testContentResource{key: "r1", content: `invalid&toml"`, mime: media.Builtin.TOMLType}, nil, false},