Skip to content

Commit 06b0ddd

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

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
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) {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public function testAskReturnsNullIfValidatorAllowsIt()
7979
$questionHelper = new SymfonyQuestionHelper();
8080
$questionHelper->setInputStream($this->getInputStream("\n"));
8181
$question = new Question('What is your favorite superhero?');
82-
$question->setValidator(function ($value) { return $value; });
82+
$question->setValidator(function ($value) {
83+
return $value;
84+
});
8385
$this->assertNull($questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
8486
}
8587

@@ -101,6 +103,15 @@ public function testAskEscapeLabel()
101103
$this->assertOutputContains('Do you want a \?', $output);
102104
}
103105

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

0 commit comments

Comments
 (0)