bug #23730 Fixed the escaping of back slashes and << in console output (javiereguiluz)
This PR was squashed before being merged into the 2.7 branch (closes #23730).
Discussion
----------
Fixed the escaping of back slashes and << in console output
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #18481
| License | MIT
| Doc PR | -
Not sure if it's a valid solution, but this is my attempt to solve #18481.
Commits
-------
d5cb1fe711
Fixed the escaping of back slashes and << in console output
This commit is contained in:
commit
9c796b4e39
@ -50,7 +50,8 @@ class OutputFormatter implements OutputFormatterInterface
|
|||||||
if ('\\' === substr($text, -1)) {
|
if ('\\' === substr($text, -1)) {
|
||||||
$len = strlen($text);
|
$len = strlen($text);
|
||||||
$text = rtrim($text, '\\');
|
$text = rtrim($text, '\\');
|
||||||
$text .= str_repeat('<<', $len - strlen($text));
|
$text = str_replace("\0", '', $text);
|
||||||
|
$text .= str_repeat("\0", $len - strlen($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
@ -165,8 +166,8 @@ class OutputFormatter implements OutputFormatterInterface
|
|||||||
|
|
||||||
$output .= $this->applyCurrentStyle(substr($message, $offset));
|
$output .= $this->applyCurrentStyle(substr($message, $offset));
|
||||||
|
|
||||||
if (false !== strpos($output, '<<')) {
|
if (false !== strpos($output, "\0")) {
|
||||||
return strtr($output, array('\\<' => '<', '<<' => '\\'));
|
return strtr($output, array("\0" => '\\', '\\<' => '<'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return str_replace('\\<', '<', $output);
|
return str_replace('\\<', '<', $output);
|
||||||
|
@ -28,6 +28,9 @@ class OutputFormatterTest extends TestCase
|
|||||||
$formatter = new OutputFormatter(true);
|
$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 << 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>', $formatter->format('\\<info>some info\\</info>'));
|
||||||
$this->assertEquals('\\<info>some info\\</info>', OutputFormatter::escape('<info>some info</info>'));
|
$this->assertEquals('\\<info>some info\\</info>', OutputFormatter::escape('<info>some info</info>'));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user