Skip to content

Commit

Permalink
[Console] Escape exception message during the rendering of an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx authored and fabpot committed Sep 17, 2013
1 parent 1fd8652 commit c6c35b3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Command\ListCommand;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\DialogHelper;
Expand Down Expand Up @@ -827,7 +828,7 @@ public function renderException($e, $output)
$output->writeln("");
$output->writeln("");
foreach ($messages as $message) {
$output->writeln('<error>'.$message.'</error>');
$output->writeln('<error>'.OutputFormatter::escape($message).'</error>');
}
$output->writeln("");
$output->writeln("");
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -429,6 +429,9 @@ public function testRenderException()
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exceptions with previous exceptions');

$tester->run(array('command' => 'foo3:bar'), array('decorated' => true));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');

$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
$application->setAutoExit(false);
$application->expects($this->any())
Expand Down
8 changes: 6 additions & 2 deletions src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php
Expand Up @@ -17,9 +17,13 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
throw new \Exception("First exception");
try {
throw new \Exception("First exception <p>this is html</p>");
} catch (\Exception $e) {
throw new \Exception("Second exception <comment>comment<comment>", 0, $e);
}
} catch (\Exception $e) {
throw new \Exception("Second exception", 0, $e);
throw new \Exception("Third exception <fg=blue;bg=red>comment</>", 0, $e);
}
}
}
@@ -1,17 +1,25 @@



[Exception]
Second exception

[Exception]
Third exception <fg=blue;bg=red>comment</>





[Exception]
First exception


[Exception]
Second exception <comment>comment<comment>






[Exception]
First exception <p>this is html</p>



foo3:bar
Expand Down
@@ -0,0 +1,27 @@


 
 [Exception] 
 Third exception <fg=blue;bg=red>comment</> 
 




 
 [Exception] 
 Second exception <comment>comment<comment> 
 




 
 [Exception] 
 First exception <p>this is html</p> 
 


foo3:bar


0 comments on commit c6c35b3

Please sign in to comment.