Repository navigation
text: Preserve sparse Markdown table rows - #3673
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Markdown table conversion currently pads every parsed row to the header width with default
TableCellvalues. A wide header and many one-cell body rows therefore turn O(columns + rows) input into O(columns × rows) retained cells. Each synthesized cell owns a defaultParagraphwith Arc-backed state. This can exhaust an embedding application's memory when it renders attacker-influenced Markdown.Keep missing cells implicit and continue truncating excess cells to the GFM header width. The existing renderer iterates the shared column grid and reads optional cell content with
row.children.get(ix), so stored placeholder paragraphs are unnecessary. Add a bounded sparse-cell regression and update the ragged-row test to cover short rows, excess cells, and an explicitly empty middle cell.The code diff is confined to
crates/base/src/text/format/markdown.rs: 48 insertions and 8 deletions. There are no public API changes.Before and after
Measured retained
TableCellcounts from the actual production Markdown converter, using identical compact inputs:The new sparse-cell regression fails with the original padding and passes with the fix. No intentional OOM or large-case crash was attempted.
Following previous contributions, English report, raw logs, the temporary production-parser probe and reproduction script are preserved at an immutable commit on a separate fork evidence branch. Evidence files are not included in this code PR.
Exposure depends on a host rendering untrusted Markdown; this library is not itself a network service. This change removes the introduced retained parser-cell expansion. It does not establish a general document budget or bounded upstream parser, layout or rendering cost. Visual alignment and end-to-end hover interaction were not exercised.
How to Test
Validated on Linux against base
69a2077cplus code commit0e7a5806:Both regression tests, Clippy and formatting passed. The recorded regression invocations omitted
--locked; Clippy used it. Omit--offlinewhen dependencies are not cached. The existing Base tests requiretest-supportin this checkout.The evidence branch's
docs/evidence/sparse-markdown-table/reproduce.pytemporarily restores the old sink, runs the same bounded probe before and after, confirms the expected regression failure/pass, and restores the source. Its complete reproduction run passed.AI Assistance
AI assisted with analysis, patch review, bounded production-parser validation, English evidence, and commit/PR preparation. The submitted fix and regression tests originated in the supplied patch. Human maintainer review remains required.
Checklist