aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoe Mooring <[email protected]>2024-10-21 17:46:53 -0700
committerBjørn Erik Pedersen <[email protected]>2024-10-22 09:42:40 +0200
commit5bbe95f9c5442898cdfb100bff4f1aac52fce5ad (patch)
tree0cd8934ee2b3fd49f4f2da73d7179ab2e36562cc
parent31d19b505d658e35ff4b1e4390c1e0fa9e41f811 (diff)
downloadhugo-5bbe95f9c5442898cdfb100bff4f1aac52fce5ad.tar.gz
hugo-5bbe95f9c5442898cdfb100bff4f1aac52fce5ad.zip
tpl/transform: Revert unmarshal whitespace removal
Fixes #12977
-rw-r--r--tpl/transform/transform_integration_test.go20
-rw-r--r--tpl/transform/unmarshal.go3
2 files changed, 20 insertions, 3 deletions
diff --git a/tpl/transform/transform_integration_test.go b/tpl/transform/transform_integration_test.go
index da8290e17..5f34ff81b 100644
--- a/tpl/transform/transform_integration_test.go
+++ b/tpl/transform/transform_integration_test.go
@@ -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}"
}}
@@ -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}}`)
+}
diff --git a/tpl/transform/unmarshal.go b/tpl/transform/unmarshal.go
index 0068947f6..a3a9c040a 100644
--- a/tpl/transform/unmarshal.go
+++ b/tpl/transform/unmarshal.go
@@ -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
}