Skip to content
/ hugo Public
forked from gohugoio/hugo

Commit

Permalink
tpl/transform: Revert unmarshal whitespace removal
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed Oct 22, 2024
1 parent 31d19b5 commit 921e59b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 19 additions & 1 deletion tpl/transform/transform_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func TestToMathMacros(t *testing.T) {
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- layouts/index.html --
{{ $macros := dict
{{ $macros := dict
"\\addBar" "\\bar{#1}"
"\\bold" "\\mathbf{#1}"
}}
Expand All @@ -261,3 +261,21 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term']
<mi>y</mi>
`)
}

// Issue #12977
func TestUnmarshalWithIndentedYAML(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- layouts/index.html --
{{ $yaml := "\n a:\n b: 1\n c:\n d: 2\n" }}
{{ $yaml | transform.Unmarshal | encoding.Jsonify }}
`

b := hugolib.Test(t, files)

b.AssertFileExists("public/index.html", true)
b.AssertFileContent("public/index.html", `{"a":{"b":1},"c":{"d":2}}`)
}
3 changes: 1 addition & 2 deletions tpl/transform/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ 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 == "" {
if strings.TrimSpace(dataStr) == "" {
return nil, nil
}

Expand Down

0 comments on commit 921e59b

Please sign in to comment.