tpl/transform: Don't fail on "no data to transform"

Fixes #12964
This commit is contained in:
Bjørn Erik Pedersen 2024-10-18 10:30:36 +02:00
parent e971b7d866
commit 42f37b4e98
No known key found for this signature in database
2 changed files with 4 additions and 1 deletions

View file

@ -112,9 +112,10 @@ func (ns *Namespace) Unmarshal(args ...any) (any, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("type %T not supported", data) return nil, fmt.Errorf("type %T not supported", data)
} }
dataStr = strings.TrimSpace(dataStr)
if dataStr == "" { if dataStr == "" {
return nil, errors.New("no data to transform") return nil, nil
} }
key := hashing.MD5FromStringHexEncoded(dataStr) key := hashing.MD5FromStringHexEncoded(dataStr)

View file

@ -139,6 +139,8 @@ func TestUnmarshal(t *testing.T) {
a;b;c`, mime: media.Builtin.CSVType}, map[string]any{"DElimiter": ";", "Comment": "%"}, func(r [][]string) { a;b;c`, mime: media.Builtin.CSVType}, map[string]any{"DElimiter": ";", "Comment": "%"}, func(r [][]string) {
b.Assert([][]string{{"a", "b", "c"}}, qt.DeepEquals, r) b.Assert([][]string{{"a", "b", "c"}}, qt.DeepEquals, r)
}}, }},
{``, nil, nil},
{` `, nil, nil},
// errors // errors
{"thisisnotavaliddataformat", nil, false}, {"thisisnotavaliddataformat", nil, false},
{testContentResource{key: "r1", content: `invalid&toml"`, mime: media.Builtin.TOMLType}, nil, false}, {testContentResource{key: "r1", content: `invalid&toml"`, mime: media.Builtin.TOMLType}, nil, false},