summaryrefslogtreecommitdiffstats
path: root/markup
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2025-02-18 09:30:47 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2025-02-18 11:12:39 +0100
commit494e88abf6007c48e51e5e065936ba88b3b75a87 (patch)
tree94b0ef6170344ff724d86e92631c4c6ad4f7bae8 /markup
parentf1e799c2e174f5d78cec46a678490b5872afcb2c (diff)
downloadhugo-494e88abf6007c48e51e5e065936ba88b3b75a87.tar.gz
hugo-494e88abf6007c48e51e5e065936ba88b3b75a87.zip
markup/goldmark: Fix panic on empty Markdown header
Fixes #13416
Diffstat (limited to 'markup')
-rw-r--r--markup/goldmark/render_hooks.go8
-rw-r--r--markup/goldmark/toc_integration_test.go22
2 files changed, 26 insertions, 4 deletions
diff --git a/markup/goldmark/render_hooks.go b/markup/goldmark/render_hooks.go
index 12cf00455..1e91f7ab1 100644
--- a/markup/goldmark/render_hooks.go
+++ b/markup/goldmark/render_hooks.go
@@ -499,10 +499,10 @@ func (r *hookedRenderer) renderHeading(w util.BufWriter, source []byte, node ast
text := ctx.PopRenderedString()
- // All ast.Heading nodes are guaranteed to have an attribute called "id"
- // that is an array of bytes that encode a valid string.
- anchori, _ := n.AttributeString("id")
- anchor := anchori.([]byte)
+ var anchor []byte
+ if anchori, ok := n.AttributeString("id"); ok {
+ anchor, _ = anchori.([]byte)
+ }
page, pageInner := render.GetPageAndPageInner(ctx)
diff --git a/markup/goldmark/toc_integration_test.go b/markup/goldmark/toc_integration_test.go
index 7ce2e8664..814ae199b 100644
--- a/markup/goldmark/toc_integration_test.go
+++ b/markup/goldmark/toc_integration_test.go
@@ -258,7 +258,29 @@ title: p7 (emoji)
`)
// emoji
+
b.AssertFileContent("public/p7/index.html", `
<li><a href="#a-snake-emoji">A &#x1f40d; emoji</a></li>
`)
}
+
+func TestIssue13416(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+-- layouts/index.html --
+Content:{{ .Content }}|
+-- layouts/_default/_markup/render-heading.html --
+-- content/_index.md --
+---
+title: home
+---
+#
+`
+
+ b := hugolib.Test(t, files)
+
+ b.AssertFileExists("public/index.html", true)
+}