Skip to content

Commit

Permalink
Merge branch '5.2' into 5.3
Browse files Browse the repository at this point in the history
* 5.2:
  [Console] Escape synopsis output
  [SecurityBundle] Link UserProviderListener to correct firewall dispatcher
  [FrameworkBundle] fix KernelBrowser::loginUser with a stateless firewall
  Document null support in NumberToLocalizedStringTransformer
  Update loader’s directory when calling ContainerConfigurator::withPath
  • Loading branch information
nicolas-grekas committed Jun 3, 2021
2 parents 0585538 + 3685a3a commit dca646d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public function renderThrowable(\Throwable $e, OutputInterface $output): void
$this->doRenderThrowable($e, $output);

if (null !== $this->runningCommand) {
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
$output->writeln(sprintf('<info>%s</info>', OutputFormatter::escape(sprintf($this->runningCommand->getSynopsis(), $this->getName()))), OutputInterface::VERBOSITY_QUIET);
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
}
}
Expand Down
17 changes: 17 additions & 0 deletions Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,23 @@ public function testRenderExceptionStackTraceContainsRootException()
$this->assertStringContainsString('Dummy type "class@anonymous" is invalid.', $tester->getDisplay(true));
}

public function testRenderExceptionEscapesLinesOfSynopsis()
{
$application = new Application();
$application->setAutoExit(false);
$application
->register('foo')
->setCode(function () {
throw new \Exception('some exception');
})
->addArgument('info')
;
$tester = new ApplicationTester($application);

$tester->run(['command' => 'foo'], ['decorated' => false]);
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_rendersynopsis_escapesline.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting of synopsis');
}

public function testRun()
{
$application = new Application();
Expand Down
3 changes: 2 additions & 1 deletion Tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public function testGetSynopsis()
$command = new \TestCommand();
$command->addOption('foo');
$command->addArgument('bar');
$this->assertEquals('namespace:name [--foo] [--] [<bar>]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
$command->addArgument('info');
$this->assertEquals('namespace:name [--foo] [--] [<bar> [<info>]]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
}

public function testAddGetUsages()
Expand Down
7 changes: 7 additions & 0 deletions Tests/Fixtures/application_rendersynopsis_escapesline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

In ApplicationTest.php line %d:

some exception


foo [<info>]

0 comments on commit dca646d

Please sign in to comment.