Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
* 3.0:
  #17676 - making the proxy instantiation compatible with ProxyManager 2.x by detecting proxy features
  #17676 - making the proxy instantiation compatible with ProxyManager 2.x by detecting proxy features
  Fix bug when using an private aliased factory service
  [Form] fix tests added by #17798 by removing `choices_as_values`
  [Form] fix FQCN in tests added by #17798
  [DependencyInjection] Remove unused parameter of private property
  bug #17798 [Form] allow `choice_label` option to be `false`
  [Form] fix tests added by #17760 with FQCN
  ChoiceFormField of type "select" could be "disabled"
  Update contributing docs
  [Console] Fix escaping of trailing backslashes
  Fix constraint validator alias being required
  [DependencyInjection] Simplified code in AutowirePass
  [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 50c745b + 2ed5e27 commit 200f109
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 200f109

Please sign in to comment.