Repository navigation
fix: prevent crash in normalizeTable when body row has more cells than header - #4222
Merged
Merged
Conversation
…n header Fixes TypeError: Cannot read properties of undefined (reading 'width') (issue #4190). When a table body row contains more cells than the header, columnWidth[j] is undefined for extra columns. Guard the width-calculation loop with Math.min and slice body rows to header column count before rendering, matching standard GFM behaviour of silently ignoring extra cells. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a normalizeTable crash when table body rows contain more cells than the header, aligning export behavior with GFM-style column limits and adding regression coverage.
Changes:
- Caps table width calculation to the number of header-defined columns.
- Drops extra body cells during Markdown rendering.
- Adds unit tests for well-formed and mismatched table row lengths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/muya/lib/utils/exportMarkdown.js |
Guards table normalization against body rows with extra cells and truncates rendered rows to header column count. |
test/unit/specs/export-markdown.spec.js |
Adds regression tests for table export behavior with matching, extra, and fewer body cells. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Jocs
added a commit
that referenced
this pull request
Jun 8, 2026
The serializeTable ragged-row coverage in tableNormalization.spec.ts duplicated the existing serializeTable — row width mismatch suite in stateToMarkdown.spec.ts (both #4222/#4190): same well-formed, extra-cell-dropped, and short-row scenarios. Keeping two suites for one behavior risks them drifting apart, so remove the redundant file and keep the single existing suite as the source of truth. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Jocs
added a commit
that referenced
this pull request
Jun 8, 2026
* test(muya): port MarkText regression cases (#4341/#4307/#4190) Port three MarkText-specific regression cases from the legacy `packages/muyajs` desktop specs into `@muyajs/core`'s own suite to lock in behavioral fidelity for the migration off legacy muyajs. Tests only — no engine changes. - #4341 nested mixed lists (ul-in-ol / ol-in-ul): PASS. The state tree from MarkdownToState nests the differing-type list under the correct list-item (no paragraph collapse), and md -> state -> md round-trips identically. Ported as structural + round-trip assertions. - #4190 table normalization (body row with more/fewer cells than the header): PASS. StateToMarkdown.serializeTable clamps each row to the header column count (extra cell dropped) and never throws. The legacy spec hand-built a malformed block tree for ExportMarkdown.normalizeTable; the muya equivalent hand-builds a malformed ITableState because a GFM round trip can never produce a ragged table. - #4307 CJK strong flanking (`**"加粗"**` against a CJK boundary): documented engine GAP. marked@16 implements the CommonMark flanking rule literally and classifies CJK ideographs / Hangul as "other" (neither whitespace nor punctuation), so `**` adjacent to a CJK char with punctuation-bounded inner content does not open/close emphasis. Legacy muyajs shipped a custom tokenizer that treats CJK as punctuation for flanking; marked does not. The four CJK cases assert the CORRECT (legacy) behavior under `it.fails`, so the suite stays green while the gap exists and flips red the moment the gap closes. Sanity cases that already work are plain `it` so a future fix can't regress them. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * test(muya): drop duplicate tableNormalization spec The serializeTable ragged-row coverage in tableNormalization.spec.ts duplicated the existing serializeTable — row width mismatch suite in stateToMarkdown.spec.ts (both #4222/#4190): same well-formed, extra-cell-dropped, and short-row scenarios. Keeping two suites for one behavior risks them drifting apart, so remove the redundant file and keep the single existing suite as the source of truth. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
thimbleberrysystems
pushed a commit
to thimbleberrysystems/WordBird
that referenced
this pull request
Jun 21, 2026
…n header (marktext#4222) Fixes TypeError: Cannot read properties of undefined (reading 'width') (issue marktext#4190). When a table body row contains more cells than the header, columnWidth[j] is undefined for extra columns. Guard the width-calculation loop with Math.min and slice body rows to header column count before rendering, matching standard GFM behaviour of silently ignoring extra cells. Co-authored-by: Claude Sonnet 4.6 <[email protected]>
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.
Closes #4190
Summary
columnWidth[j]isundefinedfor the extra columns, causingTypeError: Cannot read properties of undefined (reading 'width')innormalizeTableMath.min(tableData[i].length, columnWidth.length)and.slice(0, columnWidth.length)before the row-rendering map, silently dropping extra cells (matches GFM spec behaviour)test/unit/specs/export-markdown.spec.jswith 3 regression tests (well-formed table, body row with extra cells, body row with fewer cells)Reproduction
Create a markdown file where a body row has more columns than the header and open it in MarkText — any save/export triggers the crash:
Test plan
does not throw when a body row has more cells than the header (issue #4190)directly reproduces and verifies the fix🤖 Generated with Claude Code