diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php
index 32bd8373db221..bc5e9ee66c09b 100644
--- a/src/Symfony/Component/Console/Application.php
+++ b/src/Symfony/Component/Console/Application.php
@@ -650,12 +650,11 @@ public function renderException($e, $output)
if (defined('HHVM_VERSION') && $width > 1 << 31) {
$width = 1 << 31;
}
- $formatter = $output->getFormatter();
$lines = array();
- foreach (preg_split('/\r?\n/', OutputFormatter::escape($e->getMessage())) as $line) {
+ foreach (preg_split('/\r?\n/', $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;
+ $lineLength = $this->stringWidth($line) + 4;
$lines[] = array($line, $lineLength);
$len = max($lineLength, $len);
@@ -663,15 +662,15 @@ public function renderException($e, $output)
}
$messages = array();
- $messages[] = $emptyLine = $formatter->format(sprintf('%s', str_repeat(' ', $len)));
- $messages[] = $formatter->format(sprintf('%s%s', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title)))));
+ $messages[] = $emptyLine = sprintf('%s', str_repeat(' ', $len));
+ $messages[] = sprintf('%s%s', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title))));
foreach ($lines as $line) {
- $messages[] = $formatter->format(sprintf(' %s %s', $line[0], str_repeat(' ', $len - $line[1])));
+ $messages[] = sprintf(' %s %s', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
}
$messages[] = $emptyLine;
$messages[] = '';
- $output->writeln($messages, OutputInterface::OUTPUT_RAW);
+ $output->writeln($messages);
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
$output->writeln('Exception trace:');
diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php
index 895fdb926142f..df6d1976e7193 100644
--- a/src/Symfony/Component/Console/Tests/ApplicationTest.php
+++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php
@@ -591,6 +591,22 @@ public function testRenderExceptionWithDoubleWidthCharacters()
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth2.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal');
}
+ public function testRenderExceptionEscapesLines()
+ {
+ $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(array('getTerminalWidth'))->getMock();
+ $application->setAutoExit(false);
+ $application->expects($this->any())
+ ->method('getTerminalWidth')
+ ->will($this->returnValue(22));
+ $application->register('foo')->setCode(function () {
+ throw new \Exception('dont break here !');
+ });
+ $tester = new ApplicationTester($application);
+
+ $tester->run(array('command' => 'foo'), array('decorated' => false));
+ $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_escapeslines.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting');
+ }
+
public function testRun()
{
$application = new Application();
diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt
new file mode 100644
index 0000000000000..cf79b37a92d6e
--- /dev/null
+++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt
@@ -0,0 +1,9 @@
+
+
+ [Exception]
+ dont break here <
+ info>!
+
+
+foo
+
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy