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

Appearance settings

Commit d7524e6

Browse filesBrowse 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
Copy full SHA for d7524e6

File tree

Expand file treeCollapse file tree

4 files changed

+27
-2
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+27
-2
lines changed

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/ApplicationTest.php
+17Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Command/CommandTest.php
+2-1Lines 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()
+7Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.