Open
Description
Symfony version(s) affected
6.4
Description
When using the Console table helper, the following exception is sometimes thrown : Invalid "UTF-8" string.
. I've found the cause to be the following line, which may split an UTF-8 character badly when the cell text is wrapped on multiple line.
applyCurrentStyle
will indeed receive an Invalid "UTF-8" string because of the result of substr
:

Explanation : https://www.php.net/manual/en/function.substr.php#90581
How to reproduce
Code :
#!/usr/bin/env php
<?php
// First, run "composer require symfony/console"
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
$application = new Application();
// ... register commands
$application->register('debug')
->setCode(function (InputInterface $input, OutputInterface $output): int {
$table = new Table($output);
$table->setHeaders(['Message']);
$table->setColumnMaxWidth(0, 50);
$table->addRow([
"Usuário <strong>{{user_name}}</strong> não é válido."
]);
$table->render();
return Command::SUCCESS;
});
$application->run();
Run :
php test.php debug
Result should be :
In ByteString.php line 444:
Invalid "UTF-8" string.
debug
Possible Solution
Replacing substr
with mb_substr
on this line will solve the issue. However it might be prudent to check if mb_substr
should be used elsewhere.
Additional Context
No response