diff --git a/src/Monolog/Handler/BrowserConsoleHandler.php b/src/Monolog/Handler/BrowserConsoleHandler.php index f7afa354..2d37695e 100644 --- a/src/Monolog/Handler/BrowserConsoleHandler.php +++ b/src/Monolog/Handler/BrowserConsoleHandler.php @@ -31,12 +31,12 @@ class BrowserConsoleHandler extends AbstractProcessingHandler * * Example of formatted string: * - * You can do [blue text]{color: blue} or [green background]{background-color: green; color: white} + * You can do [[blue text]]{color: blue} or [[green background]]{background-color: green; color: white} * */ protected function getDefaultFormatter() { - return new LineFormatter('[%channel%]{macro: autolabel} [%level_name%]{font-weight: bold} %message%'); + return new LineFormatter('[[%channel%]]{macro: autolabel} [[%level_name%]]{font-weight: bold} %message%'); } /** @@ -111,7 +111,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler $args = array(self::quote('font-weight: normal')); $format = '%c' . $formatted; $self = 'Monolog\Handler\BrowserConsoleHandler'; - $format = preg_replace_callback('/\[(.*?)\]\{(.*?)\}/', function($m) use(&$args, $self) { + $format = preg_replace_callback('/\[\[(.*?)\]\]\{([^}]*)\}/s', function($m) use(&$args, $self) { $args[] = $self::quote($self::handleCustomStyles($m[2], $m[1])); $args[] = $self::quote('font-weight: normal'); return '%c' . $m[1] . '%c'; diff --git a/tests/Monolog/Handler/BrowserConsoleHandlerTest.php b/tests/Monolog/Handler/BrowserConsoleHandlerTest.php index e8e45498..b3c4c66e 100644 --- a/tests/Monolog/Handler/BrowserConsoleHandlerTest.php +++ b/tests/Monolog/Handler/BrowserConsoleHandlerTest.php @@ -29,7 +29,7 @@ class BrowserConsoleHandlerTest extends TestCase $handler = new BrowserConsoleHandler(); $handler->setFormatter($this->getIdentityFormatter()); - $handler->handle($this->getRecord(Logger::DEBUG, 'foo[bar]{color: red}')); + $handler->handle($this->getRecord(Logger::DEBUG, 'foo[[bar]]{color: red}')); $expected = <<assertEquals($expected, BrowserConsoleHandler::generateScript()); } + public function testEscaping() + { + $handler = new BrowserConsoleHandler(); + $handler->setFormatter($this->getIdentityFormatter()); + + $handler->handle($this->getRecord(Logger::DEBUG, "[foo] [[\"bar\n[baz]\"]]{color: red}")); + + $expected = <<assertEquals($expected, BrowserConsoleHandler::generateScript()); + } + + public function testAutolabel() { $handler = new BrowserConsoleHandler(); $handler->setFormatter($this->getIdentityFormatter()); - $handler->handle($this->getRecord(Logger::DEBUG, '[foo]{macro: autolabel}')); - $handler->handle($this->getRecord(Logger::DEBUG, '[bar]{macro: autolabel}')); - $handler->handle($this->getRecord(Logger::DEBUG, '[foo]{macro: autolabel}')); + $handler->handle($this->getRecord(Logger::DEBUG, '[[foo]]{macro: autolabel}')); + $handler->handle($this->getRecord(Logger::DEBUG, '[[bar]]{macro: autolabel}')); + $handler->handle($this->getRecord(Logger::DEBUG, '[[foo]]{macro: autolabel}')); $expected = <<