Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/layout-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,17 @@ const { ColSpanCell, RowSpanCell } = Cell;
table.forEach(function (row, rowIndex) {
row.forEach(function (cell) {
for (let i = 1; i < cell.rowSpan; i++) {
let targetRow = table[rowIndex + i];
if (!targetRow) {
// rowSpan extends past the last row; clamp it instead of indexing
// a missing row (mirrors how colSpan past the table width degrades).
break;
}
let rowSpanCell = new RowSpanCell(cell);
rowSpanCell.x = cell.x;
rowSpanCell.y = cell.y + i;
rowSpanCell.colSpan = cell.colSpan;
insertCell(rowSpanCell, table[rowIndex + i]);
insertCell(rowSpanCell, targetRow);
}
});
});
Expand Down
12 changes: 12 additions & 0 deletions test/issues/rowspan-overflow-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Table = require('../..');

test('a rowSpan that extends past the last row renders instead of throwing', () => {
const table = new Table();
table.push([{ content: 'aaaa bbbb', rowSpan: 2 }]);

let output;
expect(() => {
output = table.toString();
}).not.toThrow();
expect(output).toContain('aaaa bbbb');
});