[Console] fixed style creation when providing an unknown tag option

This commit is contained in:
Fabien Potencier 2014-08-07 17:53:10 +02:00
parent 72b70636ba
commit 88149209ae
2 changed files with 6 additions and 2 deletions

View File

@ -215,7 +215,11 @@ class OutputFormatter implements OutputFormatterInterface
} elseif ('bg' == $match[0]) {
$style->setBackground($match[1]);
} else {
$style->setOption($match[1]);
try {
$style->setOption($match[1]);
} catch (\InvalidArgumentException $e) {
return false;
}
}
}

View File

@ -151,7 +151,7 @@ class OutputFormatterTest extends \PHPUnit_Framework_TestCase
{
$formatter = new OutputFormatter(true);
$this->assertEquals("\033[32msome \033[0m\033[32m<tag>\033[0m\033[32m styled \033[0m\033[32m<p>\033[0m\033[32msingle-char tag\033[0m\033[32m</p>\033[0m", $formatter->format('<info>some <tag> styled <p>single-char tag</p></info>'));
$this->assertEquals("\033[32msome \033[0m\033[32m<tag>\033[0m\033[32m \033[0m\033[32m<setting=value>\033[0m\033[32m styled \033[0m\033[32m<p>\033[0m\033[32msingle-char tag\033[0m\033[32m</p>\033[0m", $formatter->format('<info>some <tag> <setting=value> styled <p>single-char tag</p></info>'));
}
public function testFormatLongString()