Skip to content

Commit b52d81f

Browse files
committed
[Console] Fix question formatting using SymfonyStyle::ask()
1 parent 0a4a92b commit b52d81f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
5353
*/
5454
protected function writePrompt(OutputInterface $output, Question $question)
5555
{
56-
$text = OutputFormatter::escape($question->getQuestion());
56+
$text = $question->getQuestion();
5757
$default = $question->getDefault();
5858

5959
switch (true) {
@@ -89,7 +89,7 @@ protected function writePrompt(OutputInterface $output, Question $question)
8989
$text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default));
9090
}
9191

92-
$output->writeln($text);
92+
$output->writeln($output->getFormatter()->format($text));
9393

9494
if ($question instanceof ChoiceQuestion) {
9595
$width = max(array_map('strlen', array_keys($question->getChoices())));

src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ public function testAskEscapeLabel()
101101
$this->assertOutputContains('Do you want a \?', $output);
102102
}
103103

104+
public function testAskEscapeAndFormatLabel()
105+
{
106+
$helper = new SymfonyQuestionHelper();
107+
$helper->setInputStream($this->getInputStream('Foo\\Bar'));
108+
$helper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), new Question('Do you want to use Foo\\Bar <comment>or</comment> Foo\\Baz\\?', 'Foo\\Baz'));
109+
110+
$this->assertOutputContains('Do you want to use Foo\\Bar or Foo\\Baz\\? [Foo\\Baz]:', $output);
111+
}
112+
104113
/**
105114
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
106115
* @expectedExceptionMessage Aborted

0 commit comments

Comments
 (0)