Skip to content

Commit 10eedde

Browse files
committed
Fix table trailing backslash
1 parent adb5118 commit 10eedde

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Helper/Table.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Console\Exception\InvalidArgumentException;
1515
use Symfony\Component\Console\Exception\RuntimeException;
16+
use Symfony\Component\Console\Formatter\OutputFormatter;
1617
use Symfony\Component\Console\Formatter\WrappableOutputFormatterInterface;
1718
use Symfony\Component\Console\Output\ConsoleSectionOutput;
1819
use Symfony\Component\Console\Output\OutputInterface;
@@ -528,6 +529,8 @@ private function buildTableRows($rows)
528529
if (!strstr($cell, "\n")) {
529530
continue;
530531
}
532+
$escaped = implode("\n", array_map([OutputFormatter::class, 'escapeTrailingBackslash'], explode("\n", $cell)));
533+
$cell = $cell instanceof TableCell ? new TableCell($escaped, ['colspan' => $cell->getColspan()]) : $escaped;
531534
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
532535
foreach ($lines as $lineKey => $line) {
533536
if ($cell instanceof TableCell) {

Tests/Helper/TableTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,26 @@ public function testColumnMaxWidths()
10721072
| | ities | | |
10731073
+---------------+-------+------------+-----------------+
10741074
1075+
TABLE;
1076+
1077+
$this->assertEquals($expected, $this->getOutputContent($output));
1078+
}
1079+
1080+
public function testColumnMaxWidthsWithTrailingBackslash()
1081+
{
1082+
(new Table($output = $this->getOutputStream()))
1083+
->setColumnMaxWidth(0, 5)
1084+
->setRows([['1234\6']])
1085+
->render()
1086+
;
1087+
1088+
$expected =
1089+
<<<'TABLE'
1090+
+-------+
1091+
| 1234\ |
1092+
| 6 |
1093+
+-------+
1094+
10751095
TABLE;
10761096

10771097
$this->assertEquals($expected, $this->getOutputContent($output));

0 commit comments

Comments
 (0)