Skip to content

Commit 5bbe95f

Browse files
jmooringbep
authored andcommitted
tpl/transform: Revert unmarshal whitespace removal
Fixes #12977
1 parent 31d19b5 commit 5bbe95f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

tpl/transform/transform_integration_test.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func TestToMathMacros(t *testing.T) {
248248
-- hugo.toml --
249249
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
250250
-- layouts/index.html --
251-
{{ $macros := dict
251+
{{ $macros := dict
252252
"\\addBar" "\\bar{#1}"
253253
"\\bold" "\\mathbf{#1}"
254254
}}
@@ -261,3 +261,21 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term']
261261
<mi>y</mi>
262262
`)
263263
}
264+
265+
// Issue #12977
266+
func TestUnmarshalWithIndentedYAML(t *testing.T) {
267+
t.Parallel()
268+
269+
files := `
270+
-- hugo.toml --
271+
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
272+
-- layouts/index.html --
273+
{{ $yaml := "\n a:\n b: 1\n c:\n d: 2\n" }}
274+
{{ $yaml | transform.Unmarshal | encoding.Jsonify }}
275+
`
276+
277+
b := hugolib.Test(t, files)
278+
279+
b.AssertFileExists("public/index.html", true)
280+
b.AssertFileContent("public/index.html", `{"a":{"b":1},"c":{"d":2}}`)
281+
}

tpl/transform/unmarshal.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ 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)
116115

117-
if dataStr == "" {
116+
if strings.TrimSpace(dataStr) == "" {
118117
return nil, nil
119118
}
120119

0 commit comments

Comments
 (0)