[Console] Make style formatter matching less greedy to avoid having to escape when not needed

This commit is contained in:
Jordi Boggiano 2013-01-08 17:05:32 +01:00
parent 87160a7051
commit 8ca1b805ce
2 changed files with 11 additions and 1 deletions

View File

@ -23,7 +23,7 @@ class OutputFormatter implements OutputFormatterInterface
/**
* The pattern to phrase the format.
*/
const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]+)?>((?:(?!\\\\?<).)*)#is';
const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]+)?>((?:(?!\\\\?<(?:/?[a-z]|/>)).)*)#is';
private $decorated;
private $styles = array();

View File

@ -73,6 +73,16 @@ class FormatterStyleTest extends \PHPUnit_Framework_TestCase
);
}
public function testStyleMatchingNotGreedy()
{
$formatter = new OutputFormatter(true);
$this->assertEquals(
"(\033[32m>=2.0,<2.3\033[0m)",
$formatter->format('(<info>>=2.0,<2.3</info>)')
);
}
public function testDeepNestedStyles()
{
$formatter = new OutputFormatter(true);