diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php index 154a041dae..e0bbd06705 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php @@ -33,6 +33,20 @@ class OutputFormatter implements OutputFormatterInterface { $text = preg_replace('/([^\\\\]?)getQuestion(); + $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion()); $default = $question->getDefault(); switch (true) { diff --git a/src/Symfony/Component/Console/Style/SymfonyStyle.php b/src/Symfony/Component/Console/Style/SymfonyStyle.php index e9932d1f87..a1a0fb8c2e 100644 --- a/src/Symfony/Component/Console/Style/SymfonyStyle.php +++ b/src/Symfony/Component/Console/Style/SymfonyStyle.php @@ -121,7 +121,7 @@ class SymfonyStyle extends OutputStyle { $this->autoPrependBlock(); $this->writeln(array( - sprintf('%s', $message), + sprintf('%s', OutputFormatter::escapeTrailingBackslash($message)), sprintf('%s', str_repeat('=', strlen($message))), )); $this->newLine(); @@ -134,7 +134,7 @@ class SymfonyStyle extends OutputStyle { $this->autoPrependBlock(); $this->writeln(array( - sprintf('%s', $message), + sprintf('%s', OutputFormatter::escapeTrailingBackslash($message)), sprintf('%s', str_repeat('-', strlen($message))), )); $this->newLine(); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php new file mode 100644 index 0000000000..e6a13558d0 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/command/command_12.php @@ -0,0 +1,13 @@ +title('Title ending with \\'); + $output->section('Section ending with \\'); +}; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_12.txt b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_12.txt new file mode 100644 index 0000000000..59d00e04a2 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/Style/SymfonyStyle/output/output_12.txt @@ -0,0 +1,7 @@ + +Title ending with \ +=================== + +Section ending with \ +--------------------- + diff --git a/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php index e26a254baa..ed4adef52e 100644 --- a/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php @@ -79,9 +79,7 @@ class SymfonyQuestionHelperTest extends \PHPUnit_Framework_TestCase $questionHelper = new SymfonyQuestionHelper(); $questionHelper->setInputStream($this->getInputStream("\n")); $question = new Question('What is your favorite superhero?'); - $question->setValidator(function ($value) { - return $value; - }); + $question->setValidator(function ($value) { return $value; }); $this->assertNull($questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question)); } @@ -103,6 +101,15 @@ class SymfonyQuestionHelperTest extends \PHPUnit_Framework_TestCase $this->assertOutputContains('Do you want to use Foo\\Bar or Foo\\Baz\\? [Foo\\Baz]:', $output); } + public function testLabelTrailingBackslash() + { + $helper = new SymfonyQuestionHelper(); + $helper->setInputStream($this->getInputStream('sure')); + $helper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), new Question('Question with a trailing \\')); + + $this->assertOutputContains('Question with a trailing \\', $output); + } + /** * @expectedException \Symfony\Component\Console\Exception\RuntimeException * @expectedExceptionMessage Aborted