Fix table trailing backslash
This commit is contained in:
parent
1628995268
commit
48f020f9e3
@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Helper;
|
|||||||
|
|
||||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\Console\Exception\RuntimeException;
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
|
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||||
use Symfony\Component\Console\Formatter\WrappableOutputFormatterInterface;
|
use Symfony\Component\Console\Formatter\WrappableOutputFormatterInterface;
|
||||||
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
@ -528,6 +529,8 @@ class Table
|
|||||||
if (!strstr($cell, "\n")) {
|
if (!strstr($cell, "\n")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$escaped = implode("\n", array_map([OutputFormatter::class, 'escapeTrailingBackslash'], explode("\n", $cell)));
|
||||||
|
$cell = $cell instanceof TableCell ? new TableCell($escaped, ['colspan' => $cell->getColspan()]) : $escaped;
|
||||||
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
|
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
|
||||||
foreach ($lines as $lineKey => $line) {
|
foreach ($lines as $lineKey => $line) {
|
||||||
if ($cell instanceof TableCell) {
|
if ($cell instanceof TableCell) {
|
||||||
|
@ -1072,6 +1072,26 @@ TABLE
|
|||||||
| | ities | | |
|
| | ities | | |
|
||||||
+---------------+-------+------------+-----------------+
|
+---------------+-------+------------+-----------------+
|
||||||
|
|
||||||
|
TABLE;
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testColumnMaxWidthsWithTrailingBackslash()
|
||||||
|
{
|
||||||
|
(new Table($output = $this->getOutputStream()))
|
||||||
|
->setColumnMaxWidth(0, 5)
|
||||||
|
->setRows([['1234\6']])
|
||||||
|
->render()
|
||||||
|
;
|
||||||
|
|
||||||
|
$expected =
|
||||||
|
<<<'TABLE'
|
||||||
|
+-------+
|
||||||
|
| 1234\ |
|
||||||
|
| 6 |
|
||||||
|
+-------+
|
||||||
|
|
||||||
TABLE;
|
TABLE;
|
||||||
|
|
||||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||||
|
Reference in New Issue
Block a user