From 691d7bc7cd28eba3edb6352b68fdea8eb62bdc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 17 Jan 2024 09:53:10 +0100 Subject: [PATCH] Fix panic with empty taxonomy param --- hugolib/content_map_page.go | 3 +++ hugolib/pagecollections_test.go | 24 ++++++++++++++++++++++++ hugolib/taxonomy_test.go | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index 4f98589519c..d0caf95a496 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -1315,6 +1315,9 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error { } for i, v := range vals { + if v == "" { + continue + } viewTermKey := "/" + viewName.plural + "/" + v pi := sa.Site.Conf.PathParser().Parse(files.ComponentFolderContent, viewTermKey+"/_index.md") term := pages.Get(pi.Base()) diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go index 314eb48c8fc..6dff75cea36 100644 --- a/hugolib/pagecollections_test.go +++ b/hugolib/pagecollections_test.go @@ -410,6 +410,30 @@ title: p2 b.AssertFileContent("public/s1/p2/index.html", "OK: p2") } +func TestGetPageBundleToRegular2(t *testing.T) { + files := ` +-- hugo.toml -- +-- content/s1/p1/index.md -- +--- +title: p1 +--- +-- content/s1/p2.md -- +--- +title: p2 +--- +-- content/p2.md -- +--- +title: p2_root +--- +-- layouts/_default/single.html -- +../p2: {{ with .GetPage "../p2" }}{{ .Title }}{{ end }}| +` + + b := Test(t, files) + b.AssertFileContent("public/s1/p1/index.html", "../p2: p2_root|") + b.AssertFileContent("public/s1/p1/index.html", "../p2: p2_root|") +} + // https://github.com/gohugoio/hugo/issues/7016 func TestGetPageMultilingual(t *testing.T) { b := newTestSitesBuilder(t) diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go index 61ab5b8d972..3132cc48520 100644 --- a/hugolib/taxonomy_test.go +++ b/hugolib/taxonomy_test.go @@ -739,3 +739,22 @@ tags_weight: 40 b.AssertFileContent("public/index.html", `:/p1/|/p3/|/p2/|:`) } + +func TestTaxonomiesEmptyTagsString(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +[taxonomies] +tag = 'tags' +-- content/p1.md -- ++++ +title = "P1" +tags = '' ++++ +-- layouts/_default/single.html -- +Single. + +` + Test(t, files) +}