Skip to content

Fix MarkupError crash when hovering a Markdown table cell with bracketed text - #6644

Open
jryyangjy wants to merge 1 commit into
Textualize:mainfrom
jryyangjy:fix/markdown-table-tooltip-markup-crash
Open

Fix MarkupError crash when hovering a Markdown table cell with bracketed text#6644
jryyangjy wants to merge 1 commit into
Textualize:mainfrom
jryyangjy:fix/markdown-table-tooltip-markup-crash

Conversation

@jryyangjy

Copy link
Copy Markdown

Problem

MarkdownTableContent.compose() sets a table cell's tooltip from cell.plain -- a plain str extracted from the cell's Content:

yield MarkdownTableCellContents(
    cell,
    classes=f"row{row_index} cell",
    name=f"cell{row_index}.{cell_index}",
).with_tooltip(cell.plain)

Tooltips set from a str are rendered with markup enabled (Static.update() -> visualize(..., markup=self._render_markup) -> Content.from_markup(obj), see textual/visual.py). If the cell's text happens to contain something that looks like markup -- e.g. ([sys:LOCK=SAFE…]) -- hovering the cell raises MarkupError and crashes the app.

The streaming path (_update_rows, used when a Markdown widget is fed incrementally via get_stream) already avoids this by passing the Content object directly: .with_tooltip(cell). Because Content already implements the Visual protocol, visualize() returns it unchanged and never re-parses it as markup. Header cell tooltips (.with_tooltip(header), a few lines above) already do this correctly too -- only the row-cell path in compose() had the bug.

Verification

Reproduced the crash headlessly with run_test() (no real terminal needed), using the exact repro from the issue:

HEADER = "| session | note |
| --- | --- |
"
SAFE_ROW = "| aaa-bbb-ccc | first row padding to force truncation |
"
BRACKET_ROW = (
    "| 019f314b-d61d-7837-a158-8aac342ae56f "
    "| ([sys:LOCK=SAFE…]) persona override |
"
)
  • On main: the bracketed cell's tooltip is a plain str, and rendering it with markup enabled raises textual.markup.MarkupError: Expected markup value (found '…]) persona override').
  • After the fix: the tooltip is the Content object, and rendering it raises nothing.
  • Confirmed with a real editable install of this branch in an isolated venv (not just source inspection) -- ran the assertion both ways by stashing/restoring the source change to make sure the added test actually fails without the fix and passes with it.

Fix

  • _markdown.py: pass cell instead of cell.plain to with_tooltip() in the one-shot compose() path, matching the existing streaming path and the header-tooltip path.
  • Added a regression test (test_markdown_table_cell_tooltip_with_bracketed_text_does_not_crash) that mounts a one-shot markdown table with bracketed cell text and asserts every cell's tooltip renders (via visualize(..., markup=True)) without raising.
  • Added a CHANGELOG entry under ## Unreleased, following this repo's existing pattern for in-progress fixes.

Testing

  • pytest tests/test_markdown.py: 26 passed (including the new regression test).
  • pytest tests/snapshot_tests/test_snapshots.py -k markdown: 10 passed, 1 pre-existing failure (test_text_area_language_rendering[markdown], a TextArea syntax-highlighting snapshot unrelated to this change -- confirmed it fails identically on unmodified main, likely a local font/terminal rendering mismatch against the reference snapshot).

Fixes #6642

MarkdownTableContent.compose() set table-cell tooltips from cell.plain
(a plain str), which is rendered with markup enabled. Cell text that
happens to look like markup (e.g. contains "[...]") is then mis-parsed
and raises MarkupError, crashing the app on hover.

The streaming path (_update_rows) already passes the Content object
directly, which is never markup-parsed. Do the same in compose() for
consistency, matching how header tooltips are already handled.

Fixes Textualize#6642
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.

Markdown table cell tooltip crashes with MarkupError on bracketed text

1 participant