Skip to content

Commit

Permalink
tpl/transform: Don't fail on "no data to transform"
Browse files Browse the repository at this point in the history
Fixes #12964
  • Loading branch information
bep committed Oct 18, 2024
1 parent e971b7d commit 42f37b4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tpl/transform/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tpl/transform/unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 42f37b4

Please sign in to comment.