Skip to content

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

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 6 commits 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
5 changes: 3 additions & 2 deletions UPGRADE-2.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,9 @@
}
```

* The method `ExecutionContext::addViolationAtSubPath()` was deprecated and
will be removed in Symfony 2.3. You should use `addViolationAt()` instead.
* The methods `ExecutionContext::addViolationAtSubPath()` and
`ExecutionContext::addViolationAtPath()` were deprecated and will be
removed in Symfony 2.3. You should use `addViolationAt()` instead.

Before:

Expand Down
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


13 changes: 11 additions & 2 deletions src/Symfony/Component/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public function add($node)
*
* @param string $content A string to parse as HTML/XML
* @param null|string $type The content type of the string
*
* @return null|void
*/
public function addContent($content, $type = null)
{
Expand Down Expand Up @@ -710,6 +708,11 @@ public static function xpathLiteral($s)
return sprintf("concat(%s)", implode($parts, ', '));
}

/**
* @param integer $position
*
* @return \DOMElement|null
*/
private function getNode($position)
{
foreach ($this as $i => $node) {
Expand All @@ -723,6 +726,12 @@ private function getNode($position)
// @codeCoverageIgnoreEnd
}

/**
* @param \DOMElement $node
* @param string $siblingDir
*
* @return array
*/
private function sibling($node, $siblingDir = 'nextSibling')
{
$nodes = array();
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Translation/PluralizationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ public static function get($number, $locale)
* @param string $rule A PHP callable
* @param string $locale The locale
*
* @return null
*
* @throws \LogicException
*/
public static function set($rule, $locale)
Expand Down