bug #22142 [Console] Escape exception messages in renderException (chalasr)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] Escape exception messages in renderException

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22021
| License       | MIT
| Doc PR        | n/a

Adding style on exception messages should be prevented, it leads to weird results.

> Allowing formatting in them would be a nightmare, given that Symfony itself applies some formatting when rendering the exception.

Commits
-------

cb1348231a [Console] Escape exception messages
This commit is contained in:
Fabien Potencier 2017-03-27 07:36:47 -07:00
commit 46cf21506c
3 changed files with 19 additions and 18 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Console;
use Symfony\Component\Console\Descriptor\TextDescriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\DebugFormatterHelper;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Helper\QuestionHelper;
@ -651,7 +652,7 @@ class Application
}
$formatter = $output->getFormatter();
$lines = array();
foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
foreach (preg_split('/\r?\n/', OutputFormatter::escape($e->getMessage())) as $line) {
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
// pre-format lines to get the right string length
$lineLength = $this->stringWidth(preg_replace('/\[[^m]*m/', '', $formatter->format($line))) + 4;

View File

@ -1,13 +1,13 @@
[Exception]
Third exception comment
[Exception]
Third exception <fg=blue;bg=red>comment</>
[Exception]
Second exception comment
[Exception]
Second exception <comment>comment</comment>
[Exception]

View File

@ -1,17 +1,17 @@
 
 [Exception] 
 Third exception comment 
 
 
 [Exception] 
 Third exception <fg=blue;bg=red>comment</> 
 
 
 [Exception] 
 Second exception comment 
 
 
 [Exception] 
 Second exception <comment>comment</comment> 
 
 
 [Exception] 
 First exception <p>this is html</p> 
 First exception <p>this is html</p> 
 
foo3:bar