Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 960cb52

Browse files
jschaedlnicolas-grekas
authored andcommitted
[Console] Escape synopsis output
1 parent 53d9b10 commit 960cb52

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)