Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Open
Description
Symfony version(s) affected
6.4
Description
When using the Consoletable 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 ofsubstr
:

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';useSymfony\Component\Console\Application;useSymfony\Component\Console\Command\Command;useSymfony\Component\Console\Helper\Table;useSymfony\Component\Console\Input\InputInterface;useSymfony\Component\Console\Output\OutputInterface;$application =newApplication();// ... register commands$application->register('debug') ->setCode(function (InputInterface$input,OutputInterface$output):int {$table =newTable($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
Replacingsubstr
withmb_substr
onthis line will solve the issue. However it might be prudent to check ifmb_substr
should be used elsewhere.
Additional Context
No response