Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strikethrough in markdown heading triggers runtime error #11783

Closed
lyind opened this issue Dec 5, 2023 · 4 comments · Fixed by #11784
Closed

Strikethrough in markdown heading triggers runtime error #11783

lyind opened this issue Dec 5, 2023 · 4 comments · Fixed by #11784

Comments

@lyind
Copy link
Contributor

lyind commented Dec 5, 2023

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:

lyind added a commit to lyind/hugo that referenced this issue Dec 5, 2023
Configure the TOC (TableOfContents, toc.go) goldmark renderer to always
enable the Strikethrough extension. This allows handling ast.KindStrikethrough
within an AST node.

Fixes gohugoio#7169
Fixes gohugoio#8087
Fixes gohugoio#11783
@jmooring
Copy link
Member

jmooring commented Dec 6, 2023

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

@lyind
Copy link
Contributor Author

lyind commented Dec 6, 2023 via email

@lyind
Copy link
Contributor Author

lyind commented Dec 6, 2023

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 lyind changed the title Runtime Error when rendering TOC with Strikethrough Runtime Error rendering Strike-through AST Node Dec 6, 2023
@bep bep removed the NeedsTriage label Dec 6, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
lyind added a commit to lyind/hugo that referenced this issue Dec 7, 2023
Configure the TOC (TableOfContents, toc.go) goldmark renderer to always
enable the Strikethrough extension. This allows handling ast.KindStrikethrough
within an AST node.

Fixes gohugoio#7169
Fixes gohugoio#8087
Fixes gohugoio#11783
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
lyind added a commit to lyind/hugo that referenced this issue Feb 9, 2024
Configure the TOC (TableOfContents, toc.go) goldmark renderer to always
enable the Strikethrough extension. This allows handling ast.KindStrikethrough
within an AST node.

The last test in TestEscapeToc() is corrected to not expect <div>
elements to be included in the TOC renderer output.

Fixes gohugoio#7169
Fixes gohugoio#8087
Fixes gohugoio#11783
lyind added a commit to lyind/hugo that referenced this issue Feb 9, 2024
Configure the TOC (TableOfContents, toc.go) goldmark renderer to always
enable the Strikethrough extension. This allows handling ast.KindStrikethrough
within an AST node.

The last test in TestEscapeToc() is corrected to not expect <div>
elements to be included in the TOC renderer output.

Fixes gohugoio#7169
Fixes gohugoio#8087
Fixes gohugoio#11783
@jmooring jmooring changed the title Runtime Error rendering Strike-through AST Node Strikethrough in markdown heading triggers runtime error Feb 10, 2024
lyind added a commit to lyind/hugo that referenced this issue Feb 20, 2024
Configure the TOC (TableOfContents, toc.go) goldmark renderer to always
enable the Strikethrough and Emoji extensions. This allows handling
ast.KindStrikethrough and ast.KindEmoji AST nodes when rendering the TOC.

Fixes gohugoio#7169
Fixes gohugoio#11783
Fixes gohugoio#12022
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep closed this as completed in #11784 Mar 7, 2024
@bep bep closed this as completed in 134e7d1 Mar 7, 2024
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants