diff options
author | Paul Gottschling <paul.gottschling@gmail.com> | 2021-12-17 02:35:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-17 08:35:21 +0100 |
commit | 5758c370eac6c4460cd6bb34d4475c8d347585f6 (patch) | |
tree | 8a9f337cf38ed842a1d011f46d43f0e58768fd5a /hugolib/template_test.go | |
parent | 8ee6de6d96a64395d27416d4f2ad7d172a2686d0 (diff) |
Allow for return partials with falsy arguments (#9298)
Partials with returns values are parsed, then inserted into a
partial return wrapper via wrapInPartialReturnWrapper in order
to assign the return value via *contextWrapper.Set. The
predefined wrapper template for partials inserts a partial's nodes
into a "with" template action in order to set dot to a
*contextWrapper within the partial. However, because "with" is
skipped if its argument is falsy, partials with falsy arguments
were not being evaluated.
This replaces the "with" action in the partial wrapper with a
"range" action that isn't skipped if .Arg is falsy.
Fixes #7528
Diffstat (limited to 'hugolib/template_test.go')
-rw-r--r-- | hugolib/template_test.go | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/hugolib/template_test.go b/hugolib/template_test.go index abb6d32f9..2908fdf71 100644 --- a/hugolib/template_test.go +++ b/hugolib/template_test.go @@ -456,22 +456,34 @@ complex: 80: 80 `, ) }) +} - c.Run("Zero argument", func(c *qt.C) { - b := newBuilder(c) - - b.WithTemplatesAdded( - "index.html", ` -Test Partials With Return Values: - -add42: fail: {{ partial "add42.tpl" 0 }} +// Issue 7528 +func TestPartialWithZeroedArgs(t *testing.T) { -`, - ) + b := newTestSitesBuilder(t) + b.WithTemplatesAdded("index.html", + ` +X{{ partial "retval" dict }}X +X{{ partial "retval" slice }}X +X{{ partial "retval" "" }}X +X{{ partial "retval" false }}X +X{{ partial "retval" 0 }}X +{{ define "partials/retval" }} + {{ return 123 }} +{{ end }}`) + + b.WithContentAdded("p.md", ``) + b.Build(BuildCfg{}) + b.AssertFileContent("public/index.html", + ` +X123X +X123X +X123X +X123X +X123X +`) - e := b.CreateSites().BuildE(BuildCfg{}) - b.Assert(e, qt.Not(qt.IsNil)) - }) } func TestPartialCached(t *testing.T) { |