From f740d7cfe0ebaec7056a8fc2b770e46b86c13ee7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 20 Dec 2025 11:26:33 +0100 Subject: [PATCH] Fix panic when 404 is backed by a content file Fixes #14283 --- hugolib/404_test.go | 21 +++++++++++++++++++++ hugolib/content_map_page_assembler.go | 1 + hugolib/doctree/nodeshifttree.go | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/hugolib/404_test.go b/hugolib/404_test.go index 90e804c2d..e1c0195f3 100644 --- a/hugolib/404_test.go +++ b/hugolib/404_test.go @@ -92,3 +92,24 @@ Not found. b.AssertFileContent("public/404.html", `Not found. Updated.`) } + +func Test404Panic14283(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +baseURL = "http://example.com/" +-- layouts/all.html -- +All. {{ .Kind }}. {{ .Title }}| +-- content/404/_index.md -- +--- +title: "404 branch" +--- +This is the 404 branch. + +` + + b := Test(t, files) // panic. + + b.AssertFileContent("public/404/index.html", "All. section. 404 branch|") +} diff --git a/hugolib/content_map_page_assembler.go b/hugolib/content_map_page_assembler.go index 48c16c2a4..7ba9ef5ab 100644 --- a/hugolib/content_map_page_assembler.go +++ b/hugolib/content_map_page_assembler.go @@ -198,6 +198,7 @@ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error { p := newHomePageMetaSource() treePages.InsertRaw(p.pathInfo.Base(), p) } + } getCascades := func(wctx *doctree.WalkContext[contentNode], s string) *page.PageMatcherParamsConfigs { diff --git a/hugolib/doctree/nodeshifttree.go b/hugolib/doctree/nodeshifttree.go index 6e87875aa..8963a610a 100644 --- a/hugolib/doctree/nodeshifttree.go +++ b/hugolib/doctree/nodeshifttree.go @@ -625,7 +625,7 @@ func (r *NodeShiftTreeWalker[T]) toT(tree *NodeShiftTree[T], v T) (T, bool) { } func (r *NodeShiftTree[T]) Has(s string) bool { - _, ok := r.get(s) + _, ok := r.GetRaw(s) return ok } -- 2.39.5