bug #13607 [Console] Fixed output bug, if escaped string in a formatted string. (tronsha)

This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes #13607).

Discussion
----------

[Console] Fixed output bug, if escaped string in a formatted string.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

If there is a escaped tag in a formatted string, the output wasn't correct.

I have add a test for this problem and integrated a solution for this.

Commits
-------

1c62eb7 [Console] Fixed output bug, if escaped string in a formatted string.
This commit is contained in:
Fabien Potencier 2015-02-08 08:25:55 +01:00
commit a43a58ccff
2 changed files with 9 additions and 3 deletions

View File

@ -150,6 +150,10 @@ class OutputFormatter implements OutputFormatterInterface
$pos = $match[1];
$text = $match[0];
if (0 != $pos && '\\' == $message[$pos - 1]) {
continue;
}
// add the text up to the next tag
$output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset));
$offset = $pos + strlen($text);
@ -164,9 +168,6 @@ class OutputFormatter implements OutputFormatterInterface
if (!$open && !$tag) {
// </>
$this->styleStack->pop();
} elseif ($pos && '\\' == $message[$pos - 1]) {
// escaped tag
$output .= $this->applyCurrentStyle($text);
} elseif (false === $style = $this->createStyleFromString(strtolower($tag))) {
$output .= $this->applyCurrentStyle($text);
} elseif ($open) {

View File

@ -101,6 +101,11 @@ class OutputFormatterTest extends \PHPUnit_Framework_TestCase
"(\033[32mz>=2.0,<a2.3\033[0m)",
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<a2.3').'</info>)')
);
$this->assertEquals(
"\033[32m<error>some error</error>\033[39m",
$formatter->format('<info>'.$formatter->escape('<error>some error</error>').'</info>')
);
}
public function testDeepNestedStyles()