fix: clamp a rowSpan that extends past the last row instead of crashing#359
Open
spokodev wants to merge 1 commit into
Open
fix: clamp a rowSpan that extends past the last row instead of crashing#359spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
A cell whose `rowSpan` reaches beyond the number of rows below it crashed
rendering with an opaque `TypeError: Cannot read properties of undefined
(reading 'length')`:
const table = new Table();
table.push([{ content: 'aaaa bbbb', rowSpan: 2 }]);
table.toString(); // throws
`addRowSpanCells` indexed `table[rowIndex + i]` without checking it exists,
then `insertCell` read `.length` off `undefined`. A `colSpan` past the
table width already degrades gracefully, and `maxHeight` already caps the
grid at `table.length`, so clamp the rowSpan the same way instead of
throwing.
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.
Problem
A cell whose
rowSpanreaches beyond the rows below it crashes rendering with an opaque internal error:This happens for any
rowSpan: Ncell with fewer thanNrows beneath it, regardless of options.Cause
addRowSpanCellsindexes the target row without checking it exists:insertCellthen reads.lengthoffundefined. The symmetricaddColSpanCellsmutates the current row in place, so it never indexes a missing row, which is whycolSpanpast the table width already degrades gracefully whilerowSpancrashes.Fix
Break out of the loop when the target row does not exist, clamping the
rowSpanto the table height. This mirrors howcolSpanpast the width behaves and matches the existingmaxHeight = table.lengthinvariant, so out-of-bounds spans render a normal table instead of throwing. In-bounds rendering is byte-for-byte unchanged.Tests
Added
test/issues/rowspan-overflow-test.jsasserting that an over-runningrowSpanrenders instead of throwing. It fails onmaster(theTypeError) and passes with the fix. Full suite is unchanged (the one pre-existingtest custom charsfailure is an unrelated no-TTY@colors/colorsartifact that also fails onmaster).