Skip to content

Commit 42f37b4

Browse files
committed
tpl/transform: Don't fail on "no data to transform"
Fixes #12964
1 parent e971b7d commit 42f37b4

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

tpl/transform/unmarshal.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ func (ns *Namespace) Unmarshal(args ...any) (any, error) {
112112
if err != nil {
113113
return nil, fmt.Errorf("type %T not supported", data)
114114
}
115+
dataStr = strings.TrimSpace(dataStr)
115116

116117
if dataStr == "" {
117-
return nil, errors.New("no data to transform")
118+
return nil, nil
118119
}
119120

120121
key := hashing.MD5FromStringHexEncoded(dataStr)

tpl/transform/unmarshal_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ func TestUnmarshal(t *testing.T) {
139139
a;b;c`, mime: media.Builtin.CSVType}, map[string]any{"DElimiter": ";", "Comment": "%"}, func(r [][]string) {
140140
b.Assert([][]string{{"a", "b", "c"}}, qt.DeepEquals, r)
141141
}},
142+
{``, nil, nil},
143+
{` `, nil, nil},
142144
// errors
143145
{"thisisnotavaliddataformat", nil, false},
144146
{testContentResource{key: "r1", content: `invalid&toml"`, mime: media.Builtin.TOMLType}, nil, false},

0 commit comments

Comments
 (0)