bug #30911 [Console] Fix table trailing backslash (maidmaid)
This PR was merged into the 4.2 branch.
Discussion
----------
[Console] Fix table trailing backslash
| Q | A
| ------------- | ---
| Branch? | 4.2
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #30725
| License | MIT
| Doc PR | /
```php
(new Table($output))
->setColumnMaxWidth(0, 5)
->setRows([['1234\6']])
->render();
;
```
before:
```
+-------+
| 1234<fg=default;bg=default> |
| 6 |
+-------+
```
after:
```
+-------+
| 1234\ |
| 6 |
+-------+
```
#EUFOSSA
Commits
-------
48f020f9e3
Fix table trailing backslash
This commit is contained in:
commit
b46ca51238
@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Helper;
|
||||
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Formatter\WrappableOutputFormatterInterface;
|
||||
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@ -528,6 +529,8 @@ class Table
|
||||
if (!strstr($cell, "\n")) {
|
||||
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));
|
||||
foreach ($lines as $lineKey => $line) {
|
||||
if ($cell instanceof TableCell) {
|
||||
|
@ -1072,6 +1072,26 @@ TABLE
|
||||
| | 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;
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
|
Reference in New Issue
Block a user