-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Umlauts are incorrectly separated by the OutputFormatter when creating a table for the console #42034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
this solution is likely wrong, because |
Indeed, this preg_replace is wrong. It not only doesn't handle utf8, but it doesn't handle character width also. |
Thanks for pointing this out @stof, I actually overlooked the fact that not all characters can be converted. So it seems like |
I have now looked into the problem and found two possible solutions. The simplest approach would first be to replace
Could be there:
The problem is that That's why I wrote another piece of code where I changed the functionality completely so that the breaks are created manually. The commit with the changes and the second approach can be found here: BitAndBlack@63ac82d I have added some tests, the previous and the new ones work. The process is also slower than the original Please write me your thoughts and let me know how we can move on. Thanks! |
Well, if we want to work with UTF-8, using |
Yes that's true, unfortunately. Which encodings do we have to deal with? Would you tell me some characters or strings for testing? |
Hey, thanks for your report! |
This bug still exists. I'm currently waiting for @stof's reply. |
Well, we don't know which encodings are used by apps using the component. But I suspect that windows-1252 might be used for instance, as that's the encoding used by cmd.exe by default for its output |
I'm sorry, but I can't solve that — I know too little about character encoding... |
Hey, thanks for your report! |
Bug still exists. |
Hey, thanks for your report! |
Bug still exists. |
This PR was merged into the 5.4 branch. Discussion ---------- [Console] Fix linewraps in `OutputFormatter` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #42034 | License | MIT | Doc PR | n/a Fix output for tables with linebreaks and special chars; ```php $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(); ``` **Before** ``` +---------------+------------+ | ISBN | Title | +---------------+------------+ | 99921-58-10-7 | A really l | | | ong title | | | that could | | | need multi | | | ple lines | +---------------+------------+ | 99921-58-10-7 | Â rèäll | | | y löng t | | | tlè thä | | | t cöüld | | | nèêd mú | | | ltîplê l | | | ínès | +---------------+------------+ ``` **After** ``` +---------------+------------+ | ISBN | Title | +---------------+------------+ | 99921-58-10-7 | A really | | | long title | | | that could | | | need | | | multiple | | | lines | +---------------+------------+ | 99921-58-10-7 | Â rèälly | | | löng tîtlè | | | thät cöüld | | | nèêd | | | múltîplê | | | línès | +---------------+------------+ ``` Commits ------- fcf86b3 [Console] Fix linewraps in OutputFormatter
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
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 methodapplyCurrentStyle
to be precise. The problem is thatpreg_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 withutf8_decode
and later encoding them again withutf8_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! 👍
The text was updated successfully, but these errors were encountered: