diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index c2ef1884f3..9e0af0d535 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -30,27 +30,37 @@ use Symfony\Component\Debug\Exception\OutOfMemoryException; class ExceptionHandler { private $debug; + private $charset; private $handler; private $caughtBuffer; private $caughtLength; private $fileLinkFormat; - public function __construct($debug = true, $fileLinkFormat = null) + public function __construct($debug = true, $charset = null, $fileLinkFormat = null) { + if (false !== strpos($charset, '%') xor false === strpos($fileLinkFormat, '%')) { + // Swap $charset and $fileLinkFormat for BC reasons + $pivot = $fileLinkFormat; + $fileLinkFormat = $charset; + $charset = $pivot; + } $this->debug = $debug; + $this->charset = $charset ?: ini_get('default_charset') ?: 'UTF-8'; $this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); } /** * Registers the exception handler. * - * @param bool $debug + * @param bool $debug Enable/disable debug mode, where the stack trace is displayed + * @param string|null $charset The charset used by exception messages + * @param string|null $fileLinkFormat The IDE link template * * @return ExceptionHandler The registered exception handler */ - public static function register($debug = true, $fileLinkFormat = null) + public static function register($debug = true, $charset = null, $fileLinkFormat = null) { - $handler = new static($debug, $fileLinkFormat); + $handler = new static($debug, $charset, $fileLinkFormat); $prev = set_exception_handler(array($handler, 'handle')); if (is_array($prev) && $prev[0] instanceof ErrorHandler) { @@ -224,7 +234,7 @@ class ExceptionHandler foreach ($exception->toArray() as $position => $e) { $ind = $count - $position + 1; $class = $this->formatClass($e['class']); - $message = nl2br(self::utf8Htmlize($e['message'])); + $message = nl2br($this->escapeHtml($e['message'])); $content .= sprintf(<< %d/%d @@ -252,7 +262,7 @@ EOF } catch (\Exception $e) { // something nasty happened and we cannot throw an exception anymore if ($this->debug) { - $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), self::utf8Htmlize($e->getMessage())); + $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this->escapeHtml($e->getMessage())); } else { $title = 'Whoops, looks like something went wrong.'; } @@ -338,7 +348,7 @@ EOF; - +