Skip to content

Commit

Permalink
Merge branch '2.7' into 2.8
Browse files Browse the repository at this point in the history
* 2.7:
  #17676 - making the proxy instantiation compatible with ProxyManager 2.x by detecting proxy features
  Fix bug when using an private aliased factory service
  ChoiceFormField of type "select" could be "disabled"
  Update contributing docs
  [Console] Fix escaping of trailing backslashes
  Fix constraint validator alias being required
  [ci] clone with depth=1 to kill push-forced PRs
  Add check on If-Range header
  • Loading branch information
fabpot committed Feb 28, 2016
2 parents fa1df6d + ee91ec3 commit 56cc5ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions Formatter/OutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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 @@ -131,7 +139,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 @@ -166,6 +174,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
4 changes: 2 additions & 2 deletions Tests/Formatter/OutputFormatterTest.php
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[39m)",
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<a2.3').'</info>)')
"(\033[32mz>=2.0,<<<a2.3\\\033[39m)",
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<\\<<a2.3\\').'</info>)')
);

$this->assertEquals(
Expand Down

0 comments on commit 56cc5ca

Please sign in to comment.