8000 Fix - #17676 (backport #17919 to 2.3) by Ocramius · Pull Request #17946 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix - #17676 (backport #17919 to 2.3) #17946

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Console] Fix escaping of trailing backslashes
  • Loading branch information
nicolas-grekas committed Feb 24, 2016
commit 44ae7850642597f8f56220bd4411d85023a64a61
16 changes: 14 additions & 2 deletions src/Symfony/Component/Console/Formatter/OutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ class OutputFormatter implements OutputFormatterInterface
*/
public static function escape($text)
{
return preg_replace('/([^\\\\]?)</', '$1\\<', $text);
$text = preg_replace('/([^\\\\]?)</', '$1\\<', $text);

if ('\\' === substr($text, -1)) {
$len = strlen($text);
$text = rtrim($text, '\\');
$text .= str_repeat('<<', $len - strlen($text));
}

return $text;
}

/**
Expand Down Expand Up @@ -129,7 +137,7 @@ public function format($message)
$message = (string) $message;
$offset = 0;
$output = '';
$tagRegex = '[a-z][a-z0-9_=;-]*';
$tagRegex = '[a-z][a-z0-9_=;-]*+';
preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE);
foreach ($matches[0] as $i => $match) {
$pos = $match[1];
Expand Down Expand Up @@ -164,6 +172,10 @@ public function format($message)

$output .= $this->applyCurrentStyle(substr($message, $offset));

if (false !== strpos($output, '<<')) {
return strtr($output, array('\\<' => '<', '<<' => '\\'));
}

return str_replace('\\<', '<', $output);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function testStyleEscaping()
$formatter = new OutputFormatter(true);

$this->assertEquals(
"(\033[32mz>=2.0,<a2.3\033[0m)",
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<a2.3').'</info>)')
"(\033[32mz>=2.0,<<<a2.3\\\033[0m)",
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<\\<<a2.3\\').'</info>)')
);

$this->assertEquals(
Expand Down
0