Skip to content

Commit 2ed5e27

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: #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
2 parents d317b8c + 56cc5ca commit 2ed5e27

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Formatter/OutputFormatter.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ class OutputFormatter implements OutputFormatterInterface
3333
*/
3434
public static function escape($text)
3535
{
36-
return preg_replace('/([^\\\\]?)</', '$1\\<', $text);
36+
$text = preg_replace('/([^\\\\]?)</', '$1\\<', $text);
37+
38+
if ('\\' === substr($text, -1)) {
39+
$len = strlen($text);
40+
$text = rtrim($text, '\\');
41+
$text .= str_repeat('<<', $len - strlen($text));
42+
}
43+
44+
return $text;
3745
}
3846

3947
/**
@@ -131,7 +139,7 @@ public function format($message)
131139
$message = (string) $message;
132140
$offset = 0;
133141
$output = '';
134-
$tagRegex = '[a-z][a-z0-9_=;-]*';
142+
$tagRegex = '[a-z][a-z0-9_=;-]*+';
135143
preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE);
136144
foreach ($matches[0] as $i => $match) {
137145
$pos = $match[1];
@@ -166,6 +174,10 @@ public function format($message)
166174

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

177+
if (false !== strpos($output, '<<')) {
178+
return strtr($output, array('\\<' => '<', '<<' => '\\'));
179+
}
180+
169181
return str_replace('\\<', '<', $output);
170182
}
171183

Tests/Formatter/OutputFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public function testStyleEscaping()
9898
$formatter = new OutputFormatter(true);
9999

100100
$this->assertEquals(
101-
"(\033[32mz>=2.0,<a2.3\033[39m)",
102-
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<a2.3').'</info>)')
101+
"(\033[32mz>=2.0,<<<a2.3\\\033[39m)",
102+
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<\\<<a2.3\\').'</info>)')
103103
);
104104

105105
$this->assertEquals(

0 commit comments

Comments
 (0)