diff --git a/Formatter/OutputFormatter.php b/Formatter/OutputFormatter.php index ca5f28731..3813b542d 100644 --- a/Formatter/OutputFormatter.php +++ b/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/Tests/Formatter/OutputFormatterTest.php b/Tests/Formatter/OutputFormatterTest.php index c8f0b987a..bdaf36cae 100644 --- a/Tests/Formatter/OutputFormatterTest.php +++ b/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()