8000 [Console] Escape exception messages · symfony/symfony@1791f32 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1791f32

Browse files
committed
[Console] Escape exception messages
1 parent 80af083 commit 1791f32

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)
0