Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd7524e6

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 parentsf143c8f +960cb52 commitd7524e6

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
privatefunctionfinishRenderThrowableOrException(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+
publicfunctiontestRenderExceptionEscapesLinesOfSynopsis()
944+
{
945+
$application =newApplication();
946+
$application->setAutoExit(false);
947+
$application
948+
->register('foo')
949+
->setCode(function () {
950+
thrownew \Exception('some exception');
951+
})
952+
->addArgument('info')
953+
;
954+
$tester =newApplicationTester($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
publicfunctiontestRun()
944961
{
945962
$application =newApplication();

‎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
publicfunctiontestAddGetUsages()
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)

[8]ページ先頭

©2009-2025 Movatter.jp