From 4da672af888cbd0db79463bf456b5210ad9a463d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 13 Jul 2023 15:01:41 +0200 Subject: [PATCH] Return error when .Render is invoked without arg Fixes #11243 --- hugolib/page__per_output.go | 3 +++ hugolib/page_test.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go index 65809a377..89dc5ac77 100644 --- a/hugolib/page__per_output.go +++ b/hugolib/page__per_output.go @@ -557,6 +557,9 @@ func (p *pageContentOutput) RenderWithTemplateInfo(ctx context.Context, info tpl } func (p *pageContentOutput) Render(ctx context.Context, layout ...string) (template.HTML, error) { + if len(layout) == 0 { + return "", errors.New("no layout given") + } templ, found, err := p.p.resolveTemplate(layout...) if err != nil { return "", p.p.wrapError(err) diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 162f26052..5237b6340 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -1983,3 +1983,25 @@ title: "p2" b.Assert(identity.HashString(p1), qt.Not(qt.Equals), identity.HashString(p2)) b.Assert(identity.HashString(sites[0]), qt.Not(qt.Equals), identity.HashString(sites[1])) } + +// Issue #11243 +func TestRenderWithoutArgument(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +-- layouts/index.html -- +{{ .Render }} +` + + b, err := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + Running: true, + }, + ).BuildE() + + b.Assert(err, qt.IsNotNil) + +}