You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using vertical style tables, whenever the component has to calculate the header width dynamically, the calculated width uses the total number of bytes of the string involved instead of the actual number of characters that would be rendered. That results in misaligned columns (and ugly tables) if the length of actual renderable characters is smaller than the next smallest length.
How to reproduce
Please note that I am using a Laravel console command for convenience only. The code that matters uses only Symfony objects and methods!
Create and run the following code inside any Laravel project. The console command may be created using php artisan make:command TestBrokenTable. Again, this is only by convenience, the affected code does not depend on Laravel! (I do not have any Symfony framework project available!)
<?phpnamespaceApp\Console\Commands;
useIlluminate\Console\Command;
useSymfony\Component\Console\Helper\Table;
useSymfony\Component\Console\Output\BufferedOutput;
classTestBrokenTableextendsCommand
{
/** * The name and signature of the console command. * * @var string */protected$signature = "app:test-broken-table";
/** * The console command description. * * @var string */protected$description = "Command description";
/** * Execute the console command. */publicfunctionhandle()
{
$headers = [
"long without MB chars",
"áéíóú MB chars", // <-- This will cause problems
"Column 3 anything",
];
// This will NOT cause problems...// $headers = [// "long without MB chars",// "aeiou MB chars",// "Column 3 anything",// ];$this->line("Middle Header:");
$this->line("Bytes: ".strlen($headers[1]));
$this->line("Chars: ".mb_strlen($headers[1]));
$data = [
[
"Shorter value",
"Value with MB chars áéíóú",
"Another Value",
],
];
$output = newBufferedOutput(decorated: true);
$table = newTable($output);
$table->setHeaders($headers);
$table->setRows($data);
$table->setVertical();
$table->render();
$text = $output->fetch();
print($text);
}
}
The output is as follows:
If I remove the multi-byte characters, the output is now correct:
If I use a table with horizontal (standard) layout, the problem does not occur.
Possible Solution
No response
Additional Context
All of the strings are in UTF-8 format.
Using Microsoft Visual Studio Code (latest update as of 2024-03-28).
Using Windows 10 Professional (latest update as of 2024-03-28).
In the above examples, "bytes" are the result of the strlen() function and "chars" the result of mb_strlen().
The text was updated successfully, but these errors were encountered:
Symfony version(s) affected
6.4.2
Description
When using vertical style tables, whenever the component has to calculate the header width dynamically, the calculated width uses the total number of bytes of the string involved instead of the actual number of characters that would be rendered. That results in misaligned columns (and ugly tables) if the length of actual renderable characters is smaller than the next smallest length.
How to reproduce
Please note that I am using a Laravel console command for convenience only. The code that matters uses only Symfony objects and methods!
Create and run the following code inside any Laravel project. The console command may be created using
php artisan make:command TestBrokenTable
. Again, this is only by convenience, the affected code does not depend on Laravel! (I do not have any Symfony framework project available!)The output is as follows:
If I remove the multi-byte characters, the output is now correct:
If I use a table with horizontal (standard) layout, the problem does not occur.
Possible Solution
No response
Additional Context
All of the strings are in UTF-8 format.
Using Microsoft Visual Studio Code (latest update as of 2024-03-28).
Using Windows 10 Professional (latest update as of 2024-03-28).
In the above examples, "bytes" are the result of the
strlen()
function and "chars" the result ofmb_strlen()
.The text was updated successfully, but these errors were encountered: