Description
Symfony version(s) affected: 5.3
Description
I noticed that umlauts lead to errors when creating a table for the Symfony console. If a row breaks into several lines and the break occurs at an umlaut, it will be destroyed. The table is then too short by a few characters.
How to reproduce
$table = new \Symfony\Component\Console\Helper\Table($output);
$table
->setColumnMaxWidth(1, 10)
->setHeaders(['ISBN', 'Title'])
->setRows([
['99921-58-10-7', 'A really long title that could need multiple lines'],
new \Symfony\Component\Console\Helper\TableSeparator(),
['99921-58-10-7', 'Â rèälly löng tîtlè thät cöüld nèêd múltîplê línès']
])
;
$table->render();
A sample code with a command class and multiple tests can be found here: https://gist.github.com/Moskito89/7774c29805248a2d2568a01997ad1bfb
Possible Solution
The problem is caused in the Symfony\Component\Console\Formatter\OutputFormatter
class. In the method applyCurrentStyle
to be precise. The problem is that preg_replace
on line 259 doesn't work with UTF8. (https://github.com/symfony/console/blob/d927f5564049730e2589d4d53c403ede528d6967/Formatter/OutputFormatter.php#L259)
This can be solved by decoding $text
and $prefix
beforehand with utf8_decode
and later encoding them again with utf8_encode
.
Please tell me if you can confirm that behaviour. Also please let me know if you want me to change that and create a PR to solve it. Thanks! 👍