Skip to content

Commit d7524e6

Browse files
bug #41386 [Console] Escape synopsis output (jschaedl)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Console] Escape synopsis output | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #41315 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Commits ------- 960cb52 [Console] Escape synopsis output
2 parents f143c8f + 960cb52 commit d7524e6

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ public function renderThrowable(\Throwable $e, OutputInterface $output): void
833833
private function finishRenderThrowableOrException(OutputInterface $output): void
834834
{
835835
if (null !== $this->runningCommand) {
836-
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
836+
$output->writeln(sprintf('<info>%s</info>', OutputFormatter::escape(sprintf($this->runningCommand->getSynopsis(), $this->getName()))), OutputInterface::VERBOSITY_QUIET);
837837
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
838838
}
839839
}

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,23 @@ public function testRenderExceptionStackTraceContainsRootException()
940940
$this->assertStringContainsString('Dummy type "class@anonymous" is invalid.', $tester->getDisplay(true));
941941
}
942942

943+
public function testRenderExceptionEscapesLinesOfSynopsis()
944+
{
945+
$application = new Application();
946+
$application->setAutoExit(false);
947+
$application
948+
->register('foo')
949+
->setCode(function () {
950+
throw new \Exception('some exception');
951+
})
952+
->addArgument('info')
953+
;
954+
$tester = new ApplicationTester($application);
955+
956+
$tester->run(['command' => 'foo'], ['decorated' => false]);
957+
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_rendersynopsis_escapesline.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting of synopsis');
958+
}
959+
943960
public function testRun()
944961
{
945962
$application = new Application();

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ public function testGetSynopsis()
192192
$command = new \TestCommand();
193193
$command->addOption('foo');
194194
$command->addArgument('bar');
195-
$this->assertEquals('namespace:name [--foo] [--] [<bar>]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
195+
$command->addArgument('info');
196+
$this->assertEquals('namespace:name [--foo] [--] [<bar> [<info>]]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
196197
}
197198

198199
public function testAddGetUsages()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
In ApplicationTest.php line %d:
3+
4+
some exception
5+
6+
7+
foo [<info>]

0 commit comments

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