hugo icon indicating copy to clipboard operation
hugo copied to clipboard

Strikethrough in markdown heading triggers runtime error

Open lyind opened this issue 2 years ago • 3 comments

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

lyind avatar Dec 05 '23 23:12 lyind

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~~](b)
# ~~a~~
# [a](b "~~c~~")

jmooring avatar Dec 06 '23 04:12 jmooring

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~~

~~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: @.***>

lyind avatar Dec 06 '23 07:12 lyind

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.

lyind avatar Dec 06 '23 07:12 lyind

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.

github-actions[bot] avatar Mar 29 '24 01:03 github-actions[bot]