8000 bug #22142 [Console] Escape exception messages in renderException (ch… · symfony/symfony@46cf215 · GitHub
[go: up one dir, main page]

Skip to content

Commit 46cf215

Browse files
committed
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 ------- cb13482 [Console] Escape exception messages
2 parents 7c5e3c0 + cb13482 commit 46cf215

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Console\Descriptor\TextDescriptor;
1515
use Symfony\Component\Console\Descriptor\XmlDescriptor;
16+
use Symfony\Component\Console\Formatter\OutputFormatter;
1617
use Symfony\Component\Console\Helper\DebugFormatterHelper;
1718
use Symfony\Component\Console\Helper\ProcessHelper;
1819
use Symfony\Component\Console\Helper\QuestionHelper;
@@ -651,7 +652,7 @@ public function renderException($e, $output)
651652
}
652653
$formatter = $output->getFormatter();
653654
$lines = array();
654-
foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
655+
foreach (preg_split('/\r?\n/', OutputFormatter::escape($e->getMessage())) as $line) {
655656
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
656657
// pre-format lines to get the right string length
657658
$lineLength = $this->stringWidth(preg_replace('/\[[^m]*m/', '', $formatter->format($line))) + 4;

src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
3-
[Exception]
4-
Third exception comment
5-
2+
3+
[Exception]
4+
Third exception <fg=blue;bg=red>comment</>
5+
66

7-
8-
[Exception]
9-
Second exception comment
10-
7+
8+
[Exception]
9+
Second exception <comment>comment</comment>
10+
1111

1212

1313
[Exception]

src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11

2-
 
3-
 [Exception] 
4-
 Third exception comment 
5-
 
2+
 
3+
 [Exception] 
4+
 Third exception <fg=blue;bg=red>comment</> 
5+
 
66

7-
 
8-
 [Exception] 
9-
 Second exception comment 
10-
 
7+
 
8+
 [Exception] 
9+
 Second exception <comment>comment</comment> 
10+
 
1111

1212
 
1313
 [Exception] 
14-
 First exception <p>this is html</p> 
14+
 First exception <p>this is html</p> 
1515
 
1616

1717
foo3:bar

0 commit comments

Comments
 (0)
0