Skip to content

Commit 3685a3a

Browse files
Merge branch '4.4' into 5.2
* 4.4: [Console] Escape synopsis output Document null support in NumberToLocalizedStringTransformer
2 parents 9e18ae5 + e3d2125 commit 3685a3a

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ public function renderThrowable(\Throwable $e, OutputInterface $output): void
795795
$this->doRenderThrowable($e, $output);
796796

797797
if (null !== $this->runningCommand) {
798-
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
798+
$output->writeln(sprintf('<info>%s</info>', OutputFormatter::escape(sprintf($this->runningCommand->getSynopsis(), $this->getName()))), OutputInterface::VERBOSITY_QUIET);
799799
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
800800
}
801801
}

Tests/ApplicationTest.php

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

930+
public function testRenderExceptionEscapesLinesOfSynopsis()
931+
{
932+
$application = new Application();
933+
$application->setAutoExit(false);
934+
$application
935+
->register('foo')
936+
->setCode(function () {
937+
throw new \Exception('some exception');
938+
})
939+
->addArgument('info')
940+
;
941+
$tester = new ApplicationTester($application);
942+
943+
$tester->run(['command' => 'foo'], ['decorated' => false]);
944+
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_rendersynopsis_escapesline.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting of synopsis');
945+
}
946+
930947
public function testRun()
931948
{
932949
$application = new Application();

Tests/Command/CommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ public function testGetSynopsis()
185185
$command = new \TestCommand();
186186
$command->addOption('foo');
187187
$command->addArgument('bar');
188-
$this->assertEquals('namespace:name [--foo] [--] [<bar>]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
188+
$command->addArgument('info');
189+
$this->assertEquals('namespace:name [--foo] [--] [<bar> [<info>]]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
189190
}
190191

191192
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)