From 2f361a8e25b64ea77ca6d4811e7a0e9bac41953b Mon Sep 17 00:00:00 2001 From: Alexandre Vaz Date: Sun, 17 May 2026 14:59:44 -0300 Subject: [PATCH] hugolib: Allow empty params front matter Treat an empty front matter params key as an empty params map instead of failing while decoding page metadata. Fixes #14886 --- hugolib/page__meta.go | 4 ++-- hugolib/rebuild_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go index 6d26c5ffd..8ca377b1c 100644 --- a/hugolib/page__meta.go +++ b/hugolib/page__meta.go @@ -655,9 +655,9 @@ params: loki := strings.ToLower(k) if loki == "params" { - vv, err := hmaps.ToStringMapE(v) + vv, err := hmaps.ToParamsAndPrepare(v) if err != nil { - return err + return fmt.Errorf("front matter field %q must be a map: %w", k, err) } userParams = vv delete(pcfg.Params, k) diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go index b3f36d442..f72bfaa31 100644 --- a/hugolib/rebuild_test.go +++ b/hugolib/rebuild_test.go @@ -398,6 +398,35 @@ func TestRebuilErrorRecovery(t *testing.T) { b.EditFileReplaceAll("content/mysection/mysectionbundle/index.md", "{{< foo }}", "{{< foo >}}").Build() } +func TestRebuildEmptyParamsIssue14886(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +baseURL = "https://example.com" +disableKinds = ["term", "taxonomy", "sitemap", "robotstxt", "404", "rss"] +disableLiveReload = true +-- content/news/_index.md -- +--- +title: News +params: + featuredImage: featured.png +--- +News. +-- layouts/list.html -- +List: {{ .Title }}|{{ .Params.featuredimage }}| +` + + b := TestRunning(t, files) + b.AssertFileContent("public/news/index.html", "List: News|featured.png|") + + b.EditFileReplaceAll("content/news/_index.md", " featuredImage", "featuredImage").Build() + b.AssertFileContent("public/news/index.html", "List: News|featured.png|") + + b.EditFileReplaceAll("content/news/_index.md", "featuredImage", " featuredImage").Build() + b.AssertFileContent("public/news/index.html", "List: News|featured.png|") +} + // Issue 14573 func TestRebuildAddContentWithMultipleDirCreations(t *testing.T) { t.Parallel()