Skip to content

[Console] Escape exception message during the rendering of an exception #9045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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