Skip to content

Commit 1c62eb7

Browse files
tronshafabpot
authored andcommitted
[Console] Fixed output bug, if escaped string in a formatted string.
1 parent d9c0c55 commit 1c62eb7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Symfony/Component/Console/Formatter/OutputFormatter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ public function format($message)
150150
$pos = $match[1];
151151
$text = $match[0];
152152

153+
if (0 != $pos && '\\' == $message[$pos - 1]) {
154+
continue;
155+
}
156+
153157
// add the text up to the next tag
154158
$output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset));
155159
$offset = $pos + strlen($text);
@@ -164,9 +168,6 @@ public function format($message)
164168
if (!$open && !$tag) {
165169
// </>
166170
$this->styleStack->pop();
167-
} elseif ($pos && '\\' == $message[$pos - 1]) {
168-
// escaped tag
169-
$output .= $this->applyCurrentStyle($text);
170171
} elseif (false === $style = $this->createStyleFromString(strtolower($tag))) {
171172
$output .= $this->applyCurrentStyle($text);
172173
} elseif ($open) {

src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public function testStyleEscaping()
101101
"(\033[32mz>=2.0,<a2.3\033[0m)",
102102
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<a2.3').'</info>)')
103103
);
104+
105+
$this->assertEquals(
106+
"\033[32m<error>some error</error>\033[39m",
107+
$formatter->format('<info>'.$formatter->escape('<error>some error</error>').'</info>')
108+
);
104109
}
105110

106111
public function testDeepNestedStyles()

0 commit comments

Comments
 (0)