diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php index ca5f28731e33..3813b542d45d 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php @@ -215,7 +215,11 @@ private function createStyleFromString($string) } elseif ('bg' == $match[0]) { $style->setBackground($match[1]); } else { - $style->setOption($match[1]); + try { + $style->setOption($match[1]); + } catch (\InvalidArgumentException $e) { + return false; + } } } diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php index c8f0b987afd1..bdaf36caef9c 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php @@ -151,7 +151,7 @@ public function testNonStyleTag() { $formatter = new OutputFormatter(true); - $this->assertEquals("\033[32msome \033[0m\033[32m\033[0m\033[32m styled \033[0m\033[32m

\033[0m\033[32msingle-char tag\033[0m\033[32m

\033[0m", $formatter->format('some styled

single-char tag

')); + $this->assertEquals("\033[32msome \033[0m\033[32m\033[0m\033[32m \033[0m\033[32m\033[0m\033[32m styled \033[0m\033[32m

\033[0m\033[32msingle-char tag\033[0m\033[32m

\033[0m", $formatter->format('some styled

single-char tag

')); } public function testFormatLongString()