Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Symfony/Component/Console/Formatter/OutputFormatter.php
Expand Up @@ -150,6 +150,10 @@ public function format($message)
$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);
Expand All @@ -164,9 +168,6 @@ public function format($message)
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) {
Expand Down
Expand Up @@ -101,6 +101,11 @@ public function testStyleEscaping()
"(\033[32mz>=2.0,<a2.3\033[39m)",
$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()
Expand Down