Skip to content

Commit

Permalink
markup/goldmark: Fix panic on empty Markdown header
Browse files Browse the repository at this point in the history
Fixes #13416
  • Loading branch information
bep committed Feb 18, 2025
1 parent f1e799c commit 494e88a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions markup/goldmark/render_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 22 additions & 0 deletions markup/goldmark/toc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 494e88a

Please sign in to comment.