diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php index 154a041dae013..e0bbd0670554c 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php @@ -33,6 +33,20 @@ public static function escape($text) { $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 e9932d1f8797d..a1a0fb8c2ee4a 100644 --- a/src/Symfony/Component/Console/Style/SymfonyStyle.php +++ b/src/Symfony/Component/Console/Style/SymfonyStyle.php @@ -121,7 +121,7 @@ public function title($message) { $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 @@ public function section($message) { $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 0000000000000..e6a13558d046c --- /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 0000000000000..59d00e04a248d --- /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 f57d65070e076..ed4adef52eb16 100644 --- a/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php @@ -92,13 +92,22 @@ public function testAskEscapeDefaultValue() $this->assertOutputContains('Can I have a backslash? [\]', $output); } - public function testAskEscapeLabel() + public function testAskEscapeAndFormatLabel() + { + $helper = new SymfonyQuestionHelper(); + $helper->setInputStream($this->getInputStream('Foo\\Bar')); + $helper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), new Question('Do you want to use Foo\\Bar or Foo\\Baz\\?', 'Foo\\Baz')); + + $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('Do you want a \?')); + $helper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), new Question('Question with a trailing \\')); - $this->assertOutputContains('Do you want a \?', $output); + $this->assertOutputContains('Question with a trailing \\', $output); } /**