Strikethrough in markdown heading triggers runtime error
What version of Hugo are you using (hugo version)?
$ hugo version v0.121.0
Does this issue reproduce with the latest release?
Yes (also tested with current master).
Summary
Hugo crashes with a similar message to
Error: error building site: render: failed to render pages: render of "term" failed: template: _internal/_default/rss.xml:67:22: executing "_internal/_default/rss.xml" at <.Summary>: error calling Summary: runtime error: index out of range [32] with length 20
when these two conditions are true:
- ~~table of contents (TOC) is generated or taxonomies are configured~~
- Markdown page contains a certain combination of ~~strike-through~~ markup
Reproduction
The problem can easily be reproduced by cloning the following repo (instruction in README.md): https://github.com/lyind/reproducer-2023-12-05
Notes
Possibly related to these auto-closed issues:
- https://github.com/gohugoio/hugo/issues/7169
- https://github.com/gohugoio/hugo/issues/8087
Whether you've configured taxonomies or are rendering a TOC is irrelevant.
Simplest way to reproduce... put this in any markdown file:
# [~~a~~](b)
It seems like the example above is unlikely to occur in the field, which is probably why this error hasn't shown up before. This isn't anything new. I can reproduce with v0.65.3 and later.
This is not an upstream issue. Goldmark 1.6.0 handles this as expected, without error:
func main() {
md := goldmark.New(
goldmark.WithExtensions(
extension.Strikethrough,
),
)
input := `
# [~~a~~](b)
`
var buf bytes.Buffer
if err := md.Convert([]byte(input), &buf); err != nil {
panic(err)
}
fmt.Println(buf.String())
}
These examples do not trigger the error:
# 
# ~~a~~
# [a](b "~~c~~")
Thank you for simplifying the reproduction.
I wasn't able to reproduce without enabling taxonomies in my setup. Maybe due to my theme.
On Wed, Dec 6, 2023, 05:39 Joe Mooring @.***> wrote:
Whether you've configured taxonomies or are rendering a TOC is irrelevant.
Simplest way to reproduce... put this in any markdown file:
~~a~~
This is not an upstream issue. Goldmark 1.6.0 handles this as expected, without error:
func main() { md := goldmark.New( goldmark.WithExtensions( extension.Strikethrough, ), )
input :=
# [~~a~~](b)var buf bytes.Buffer if err := md.Convert([]byte(input), &buf); err != nil { panic(err) }
fmt.Println(buf.String())
}
These examples do not trigger the error:
~~a~~
— Reply to this email directly, view it on GitHub https://github.com/gohugoio/hugo/issues/11783#issuecomment-1842073337, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEKSOJZ4J5K5TFJIYRSDFD3YH7ZG5AVCNFSM6AAAAABAIQD332VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBSGA3TGMZTG4 . You are receiving this because you authored the thread.Message ID: @.***>
I think the problem is that toc.go insufficiently accounts for child nodes.
Still, I'd love to fix this issue in a forward oriented way (addressing all the linked issues) and without adding more complex logic to toc.go than necessary.
I didn't fully test the effect on the rendered TOC, yet.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.