summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2025-04-14 11:55:57 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2025-04-14 14:38:22 +0200
commite8e8ce10d2b8f2eda754639dab4d20cab9613d42 (patch)
treed67090a1f87da2e92e41d7e76c5c56781a79c111
parentcf9e6904cc0850b20f9e4e378b12851bb72f44dd (diff)
downloadhugo-e8e8ce10d2b8f2eda754639dab4d20cab9613d42.tar.gz
hugo-e8e8ce10d2b8f2eda754639dab4d20cab9613d42.zip
tpl: Avoid panic on nonsensical return construct
Fixes #13600
-rw-r--r--tpl/templates/templates_integration_test.go17
-rw-r--r--tpl/tplimpl/templatetransform.go3
2 files changed, 20 insertions, 0 deletions
diff --git a/tpl/templates/templates_integration_test.go b/tpl/templates/templates_integration_test.go
index 635d521d7..7bdcdc9f0 100644
--- a/tpl/templates/templates_integration_test.go
+++ b/tpl/templates/templates_integration_test.go
@@ -262,3 +262,20 @@ Line 3.
b.Assert(err, qt.IsNotNil)
b.Assert(err.Error(), qt.Contains, filepath.FromSlash(` "/layouts/home.html:2:11": execute of template failed`))
}
+
+func TestPartialReturnPanicIssue13600(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+-- layouts/home.html --
+Partial: {{ partial "p1.html" . }}
+-- layouts/_partials/p1.html --
+P1.
+{{ return ( delimit . ", " ) | string }}
+`
+
+ b, err := hugolib.TestE(t, files)
+ b.Assert(err, qt.IsNotNil)
+ b.Assert(err.Error(), qt.Contains, "wrong number of args for string: want 1 got 0")
+}
diff --git a/tpl/tplimpl/templatetransform.go b/tpl/tplimpl/templatetransform.go
index cba4c6584..eca9fdad1 100644
--- a/tpl/tplimpl/templatetransform.go
+++ b/tpl/tplimpl/templatetransform.go
@@ -175,6 +175,9 @@ func (c *templateTransformContext) applyTransformations(n parse.Node) (bool, err
}
case *parse.CommandNode:
+ if x == nil {
+ return true, nil
+ }
c.collectInner(x)
keep := c.collectReturnNode(x)