Symfony version(s) affected
7.3.2
Description
When using $symfonyStyle->block($message) or any other related method (e.g. ->error(), ->success(), etc.) the output breaks on Windows if any \r\n newline characters are present in $message.
How to reproduce
According to my research, this only occurs on Windows machines. I was able to reproduce the issue in both Windows PowerShell and Windows Command Prompt (CMD).
Reproducer Code
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
$symfonyStyle = new SymfonyStyle(new ArrayInput([]), new ConsoleOutput());
$symfonyStyle->error("This is the first line.\r\nThis is the second line.");
Reproducer Output
Possible Solution
This is likely caused by the regular expressions used in OutputWrapper::wrap().
I don't know exactly how the method works, but it appears to replace \n with PHP_EOL when called in SymfonyStyle::createBlock(). On Windows machines, PHP_EOL is \r\n. If the original message already contains \r\n, then the wrap() method replaces this with \r\r\n. Splitting it by PHP_EOL leaves a trailing \r character. This causes the output to be broken.
How can this be solved? I'm not sure. It's either that the wrapper special handling for PHP_EOL on Windows, or the block method needs to use \n instead of PHP_EOL.
I'd like to tag the original authors of these two files for their input, if that's okay: @fchris82, @kbond?
Additional Context
I first noticed this issue while using Rector PHP, so I created an issue in their repository. I resolved the issue by replacing all occurrences of \r\n with \n. However, I think this should be solved upstream.
Symfony version(s) affected
7.3.2
Description
When using
$symfonyStyle->block($message)or any other related method (e.g.->error(),->success(), etc.) the output breaks on Windows if any\r\nnewline characters are present in$message.How to reproduce
According to my research, this only occurs on Windows machines. I was able to reproduce the issue in both Windows PowerShell and Windows Command Prompt (CMD).
Reproducer Code
Reproducer Output
Possible Solution
This is likely caused by the regular expressions used in
OutputWrapper::wrap().I don't know exactly how the method works, but it appears to replace
\nwithPHP_EOLwhen called inSymfonyStyle::createBlock(). On Windows machines,PHP_EOLis\r\n. If the original message already contains\r\n, then thewrap()method replaces this with\r\r\n. Splitting it byPHP_EOLleaves a trailing\rcharacter. This causes the output to be broken.How can this be solved? I'm not sure. It's either that the wrapper special handling for
PHP_EOLon Windows, or the block method needs to use\ninstead ofPHP_EOL.I'd like to tag the original authors of these two files for their input, if that's okay: @fchris82, @kbond?
Additional Context
I first noticed this issue while using Rector PHP, so I created an issue in their repository. I resolved the issue by replacing all occurrences of
\r\nwith\n. However, I think this should be solved upstream.