diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-07-13 15:01:41 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-07-13 18:06:36 +0200 |
commit | 4da672af888cbd0db79463bf456b5210ad9a463d (patch) | |
tree | 8f9a5a0a853f8961abfa62b1bfadaa70200d4205 /hugolib | |
parent | f1886f8c379851c45f947efd2a10424cddd338c5 (diff) |
Return error when .Render is invoked without arg
Fixes #11243
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/page__per_output.go | 3 | ||||
-rw-r--r-- | hugolib/page_test.go | 22 |
2 files changed, 25 insertions, 0 deletions
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) + +} |