bug #11609 [Console] fixed style creation when providing an unknown tag option (fabpot)

This PR was merged into the 2.3 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

When formatting a string, the console ignore style it cannot parse. But if a string looks like an option (`<setting=value>`) for instance, instead of displaying the text as is, it currently throws an exception.

Commits
-------

8814920 [Console] fixed style creation when providing an unknown tag option
This commit is contained in:
Fabien Potencier 2014-08-09 12:37:57 +02:00
commit 5b1d913174
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()