Skip to content

fix(ansi): skip nil children in emphasis and link renderers - #578

Open
SAY-5 wants to merge 1 commit into
charmbracelet:mainfrom
SAY-5:fix-nil-inline-child
Open

fix(ansi): skip nil children in emphasis and link renderers#578
SAY-5 wants to merge 1 commit into
charmbracelet:mainfrom
SAY-5:fix-nil-inline-child

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 18, 2026

Copy link
Copy Markdown

Summary

Rendering markdown where an inline element (emphasis, strong, or a link) contains a child node that has no renderer crashes with a nil pointer dereference. NewElement returns an empty Element for unhandled node kinds, so its Renderer is nil, and the inline child-collection loops append that nil straight into the Children slice. EmphasisElement.doRender and LinkElement.renderTextPart then call child.Render on it and panic. The top-level renderer already guards this with if e.Renderer != nil, but the inline renderers do not. Fixes #576.

Fix

Skip nil children in EmphasisElement.doRender and LinkElement.renderTextPart before dispatching to them, matching the guard the top-level renderer already uses.

Test

TestEmphasisRenderSkipsNilChild renders an emphasis element holding a nil child. It panics at the crash site without the fix and passes with it.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic: nil pointer dereference in inline renderers with unhandled or custom nodes

1 participant