Fixed the escaping of back slashes and << in console output

This commit is contained in:
Javier Eguiluz 2017-07-31 16:54:24 +02:00 committed by Fabien Potencier
parent 8f5141d4f7
commit d5cb1fe711
2 changed files with 7 additions and 3 deletions

View File

@ -50,7 +50,8 @@ class OutputFormatter implements OutputFormatterInterface
if ('\\' === substr($text, -1)) {
$len = strlen($text);
$text = rtrim($text, '\\');
$text .= str_repeat('<<', $len - strlen($text));
$text = str_replace("\0", '', $text);
$text .= str_repeat("\0", $len - strlen($text));
}
return $text;
@ -165,8 +166,8 @@ class OutputFormatter implements OutputFormatterInterface
$output .= $this->applyCurrentStyle(substr($message, $offset));
if (false !== strpos($output, '<<')) {
return strtr($output, array('\\<' => '<', '<<' => '\\'));
if (false !== strpos($output, "\0")) {
return strtr($output, array("\0" => '\\', '\\<' => '<'));
}
return str_replace('\\<', '<', $output);

View File

@ -28,6 +28,9 @@ class OutputFormatterTest extends TestCase
$formatter = new OutputFormatter(true);
$this->assertEquals('foo<bar', $formatter->format('foo\\<bar'));
$this->assertEquals('foo << bar', $formatter->format('foo << bar'));
$this->assertEquals('foo << bar \\', $formatter->format('foo << bar \\'));
$this->assertEquals("foo << \033[32mbar \\ baz\033[39m \\", $formatter->format('foo << <info>bar \\ baz</info> \\'));
$this->assertEquals('<info>some info</info>', $formatter->format('\\<info>some info\\</info>'));
$this->assertEquals('\\<info>some info\\</info>', OutputFormatter::escape('<info>some info</info>'));