diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-10-18 10:30:36 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-10-18 10:30:36 +0200 |
commit | 42f37b4e98e6f9621af4f1da40e831525f65fc0e (patch) | |
tree | 4ac2364b86bdeeef61aff2d8afcc7029d9688a2f | |
parent | e971b7d866d8834022f0038b094dce4352338f74 (diff) | |
download | hugo-42f37b4e98e6f9621af4f1da40e831525f65fc0e.tar.gz hugo-42f37b4e98e6f9621af4f1da40e831525f65fc0e.zip |
tpl/transform: Don't fail on "no data to transform"
Fixes #12964
-rw-r--r-- | tpl/transform/unmarshal.go | 3 | ||||
-rw-r--r-- | tpl/transform/unmarshal_test.go | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/tpl/transform/unmarshal.go b/tpl/transform/unmarshal.go index 898085661..0068947f6 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 1b976c449..d65f05fd4 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}, |