summaryrefslogtreecommitdiffstats
path: root/tpl/collections
diff options
context:
space:
mode:
authorkhayyam <ksaleem@digitalocean.com>2023-06-28 03:41:36 -0400
committerGitHub <noreply@github.com>2023-06-28 09:41:36 +0200
commitb74b8d6478c7ad68c8f3fec6597b336f55ea0a94 (patch)
treeb395bbbd97a78ee55622d1feabd2f0cf5ee4f90f /tpl/collections
parent793e38f5ce69c7eb3e70e377b21019f3eec912cb (diff)
common/collections: Fix append regression to allow appending nil
Closes #11180
Diffstat (limited to 'tpl/collections')
-rw-r--r--tpl/collections/integration_test.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/tpl/collections/integration_test.go b/tpl/collections/integration_test.go
index da1d6e488..829aee355 100644
--- a/tpl/collections/integration_test.go
+++ b/tpl/collections/integration_test.go
@@ -104,3 +104,63 @@ func TestAppendSliceToASliceOfSlices(t *testing.T) {
}
}
+
+func TestAppendNilToSlice(t *testing.T) {
+
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+-- layouts/index.html --
+{{ $obj := (slice "a") }}
+{{ $obj = $obj | append nil }}
+
+{{ $obj }}
+
+
+ `
+
+ for i := 0; i < 4; i++ {
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ },
+ ).Build()
+
+ b.AssertFileContent("public/index.html", "[a &lt;nil&gt;]")
+
+ }
+
+}
+
+func TestAppendNilsToSliceWithNils(t *testing.T) {
+
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+-- layouts/index.html --
+{{ $obj := (slice "a" nil "c") }}
+{{ $obj = $obj | append nil }}
+
+{{ $obj }}
+
+
+ `
+
+ for i := 0; i < 4; i++ {
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ },
+ ).Build()
+
+ b.AssertFileContent("public/index.html", "[a &lt;nil&gt; c &lt;nil&gt;]")
+
+ }
+
+}