Skip to content

fix(ansi): skip nil inline child renderers - #582

Open
syf2211 wants to merge 1 commit into
charmbracelet:mainfrom
syf2211:fix/nil-inline-renderer-children
Open

fix(ansi): skip nil inline child renderers#582
syf2211 wants to merge 1 commit into
charmbracelet:mainfrom
syf2211:fix/nil-inline-renderer-children

Conversation

@syf2211

@syf2211 syf2211 commented Jun 27, 2026

Copy link
Copy Markdown

Summary

Guard emphasis, link, and table cell renderers against nil children when Goldmark inline nodes are unhandled by NewElement. This prevents panics when custom or extension inline nodes appear inside inline structures.

Fixes #576

Motivation

When Glamour encounters unhandled or custom inline nodes (e.g. from Goldmark parser extensions), NewElement falls through to the default case and returns an Element with a nil Renderer. That nil value is appended to Children slices for emphasis, links, and table cells. Calling child.Render() on these nil interface values causes a nil pointer dereference panic.

Changes

  • Add nil checks in EmphasisElement.doRender, LinkElement.renderTextPart, and TableCellElement.Render before invoking child renderers
  • Add unit tests covering all three element types with a nil child followed by a valid child

Tests

  • go test ./ansi/ -run 'Test.*SkipsNilChildren' -v -count=1 — PASS
  • go test ./... -count=1 — PASS

Notes

  • Unhandled nodes still log the existing Warning: unhandled element message and produce no output; this change only prevents the panic.
  • Pre-PR review: composer-2.5 reviewed — APPROVE.

Guard emphasis, link, and table cell renderers against nil children
when Goldmark nodes are unhandled by NewElement. Prevents panics when
custom or extension inline nodes appear inside inline structures.

Fixes charmbracelet#576
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