Skip to content

Commit e8e8ce1

Browse files
committed
tpl: Avoid panic on nonsensical return construct
Fixes #13600
1 parent cf9e690 commit e8e8ce1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Diff for: tpl/templates/templates_integration_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,20 @@ Line 3.
262262
b.Assert(err, qt.IsNotNil)
263263
b.Assert(err.Error(), qt.Contains, filepath.FromSlash(` "/layouts/home.html:2:11": execute of template failed`))
264264
}
265+
266+
func TestPartialReturnPanicIssue13600(t *testing.T) {
267+
t.Parallel()
268+
269+
files := `
270+
-- hugo.toml --
271+
-- layouts/home.html --
272+
Partial: {{ partial "p1.html" . }}
273+
-- layouts/_partials/p1.html --
274+
P1.
275+
{{ return ( delimit . ", " ) | string }}
276+
`
277+
278+
b, err := hugolib.TestE(t, files)
279+
b.Assert(err, qt.IsNotNil)
280+
b.Assert(err.Error(), qt.Contains, "wrong number of args for string: want 1 got 0")
281+
}

Diff for: tpl/tplimpl/templatetransform.go

+3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ func (c *templateTransformContext) applyTransformations(n parse.Node) (bool, err
175175
}
176176

177177
case *parse.CommandNode:
178+
if x == nil {
179+
return true, nil
180+
}
178181
c.collectInner(x)
179182
keep := c.collectReturnNode(x)
180183

0 commit comments

Comments
 (0)