diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 9426f695bb..3823e9c4f6 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -343,7 +343,6 @@ class Table // Remove any new line breaks and replace it with a new line foreach ($rows[$rowKey] as $column => $cell) { - $rows[$rowKey] = $this->fillCells($rows[$rowKey], $column); if (!strstr($cell, "\n")) { continue; } @@ -363,7 +362,7 @@ class Table $tableRows = array(); foreach ($rows as $rowKey => $row) { - $tableRows[] = $row; + $tableRows[] = $this->fillCells($row); if (isset($unmergedRows[$rowKey])) { $tableRows = array_merge($tableRows, $unmergedRows[$rowKey]); } @@ -429,21 +428,23 @@ class Table * fill cells for a row that contains colspan > 1. * * @param array $row - * @param int $column * * @return array */ - private function fillCells($row, $column) + private function fillCells($row) { - $cell = $row[$column]; - if ($cell instanceof TableCell && $cell->getColspan() > 1) { - foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) { - // insert empty value into rows at column position - array_splice($row, $position, 0, ''); + $newRow = array(); + foreach ($row as $column => $cell) { + $newRow[] = $cell; + if ($cell instanceof TableCell && $cell->getColspan() > 1) { + foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) { + // insert empty value at column position + $newRow[] = ''; + } } } - return $row; + return $newRow ?: $row; } /** diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index 19bdf00e06..ab562fdb57 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -459,6 +459,24 @@ TABLE | ISBN | Title | Author | +------+-------+--------+ +TABLE + ), + 'Row with multiple cells' => array( + array(), + array( + array( + new TableCell('1', array('colspan' => 3)), + new TableCell('2', array('colspan' => 2)), + new TableCell('3', array('colspan' => 2)), + new TableCell('4', array('colspan' => 2)), + ), + ), + 'default', +<<