Skip to content

Commit

Permalink
Fix crash with empty table, table row group, or table row
Browse files Browse the repository at this point in the history
Removing or ignoring incomplete table children would be other
solutions, but the changes would be a bit more involved. This is a
quick and easy solution that is reasonable, too.

Fixes #2749
  • Loading branch information
Mellthas committed Jan 21, 2022
1 parent 8535f91 commit 0ba53a9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/FrameDecorator/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ public function normalize(): void
$tbody->append_child($child);
}

// Handle empty table: Make sure there is at least one row group
if (!$this->get_first_child()) {
$tbody = $this->create_anonymous_child("tbody", "table-row-group");
$this->append_child($tbody);
}

foreach ($this->get_children() as $child) {
$display = $child->get_style()->display;

Expand Down Expand Up @@ -343,6 +349,12 @@ private function normalizeRowGroup(AbstractFrameDecorator $frame): void
$tr->append_child($child);
}

// Handle empty row group: Make sure there is at least one row
if (!$frame->get_first_child()) {
$tr = $frame->create_anonymous_child("tr", "table-row");
$frame->append_child($tr);
}

foreach ($frame->get_children() as $child) {
$this->normalizeRow($child);
}
Expand Down Expand Up @@ -376,6 +388,12 @@ private function normalizeRow(AbstractFrameDecorator $frame): void

$td->append_child($child);
}

// Handle empty row: Make sure there is at least one cell
if (!$frame->get_first_child()) {
$td = $frame->create_anonymous_child("td", "table-cell");
$frame->append_child($td);
}
}

//........................................................................
Expand Down

0 comments on commit 0ba53a9

Please sign in to comment.