Skip to content

Commit 494e88a

Browse files
committed
markup/goldmark: Fix panic on empty Markdown header
Fixes #13416
1 parent f1e799c commit 494e88a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

markup/goldmark/render_hooks.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,10 @@ func (r *hookedRenderer) renderHeading(w util.BufWriter, source []byte, node ast
499499

500500
text := ctx.PopRenderedString()
501501

502-
// All ast.Heading nodes are guaranteed to have an attribute called "id"
503-
// that is an array of bytes that encode a valid string.
504-
anchori, _ := n.AttributeString("id")
505-
anchor := anchori.([]byte)
502+
var anchor []byte
503+
if anchori, ok := n.AttributeString("id"); ok {
504+
anchor, _ = anchori.([]byte)
505+
}
506506

507507
page, pageInner := render.GetPageAndPageInner(ctx)
508508

markup/goldmark/toc_integration_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,29 @@ title: p7 (emoji)
258258
`)
259259

260260
// emoji
261+
261262
b.AssertFileContent("public/p7/index.html", `
262263
<li><a href="#a-snake-emoji">A &#x1f40d; emoji</a></li>
263264
`)
264265
}
266+
267+
func TestIssue13416(t *testing.T) {
268+
t.Parallel()
269+
270+
files := `
271+
-- hugo.toml --
272+
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
273+
-- layouts/index.html --
274+
Content:{{ .Content }}|
275+
-- layouts/_default/_markup/render-heading.html --
276+
-- content/_index.md --
277+
---
278+
title: home
279+
---
280+
#
281+
`
282+
283+
b := hugolib.Test(t, files)
284+
285+
b.AssertFileExists("public/index.html", true)
286+
}

0 commit comments

Comments
 (0)