From eb7cbb77ec9ff4ca8143679ed66c0c9b94e08413 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 6 Sep 2010 14:58:12 +0200 Subject: [PATCH] fixed exception HTML markup (closes #9044, partially based on a patch from wrzasq) --- .../Resources/public/css/exception.css | 15 ++++++----- .../Resources/views/Exception/exception.php | 2 +- .../Resources/views/Exception/layout.php | 7 ++--- .../Resources/views/Exception/logs.php | 4 +-- .../Resources/views/Exception/trace.php | 4 +-- .../Resources/views/Exception/traces.php | 4 +-- .../Templating/Helper/CodeHelper.php | 26 +++++++++++++++++-- 7 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception.css b/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception.css index f51086210d47..479a54a15381 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception.css +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception.css @@ -16,19 +16,20 @@ build: 56 .sf-exceptionreset h3 { font-size: 130%; font-weight: bold; letter-spacing: -0.02em; } .sf-exceptionreset h3 span { float: right; font-size: 80%; background: #eee; color: #333; padding: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } .sf-exceptionreset ul { padding-left: 20px } -.sf-exceptionreset ul li { padding-bottom: 5px; list-style: decimal } -.sf-exceptionreset ol { font-family: monospace; white-space: pre; padding: 10px 0 } -.sf-exceptionreset ol li { margin: -5px; list-style: decimal; list-style-position: inside } -.sf-exceptionreset ol .selected { font-weight: bold; background-color: #ffd; padding: 2px 0 } +.sf-exceptionreset ul li { padding-bottom: 5px } +.sf-exceptionreset ol { padding: 10px 0 } +.sf-exceptionreset ol li { list-style: decimal; margin-left: 20px; padding: 2px } +.sf-exceptionreset ol ol li { list-style-position: inside; margin-left: 0 } +.sf-exceptionreset li .selected { background-color: #ffd; padding: 4px 3px } .sf-exceptionreset p.error { padding: 10px; background-color: #f00; font-weight: bold; text-align: center; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; } .sf-exceptionreset p.error a { color: #fff } -.sf-exceptionreset .block { padding: 20px 25px; margin-bottom: 10px; border: 1px solid #ddd; background-color: #fff; text-align:left; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; min-width: 770px; max-width: 770px; box-shadow: 0 1px 2px rgba(0,0,0,0.15); -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.15); -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.3); } +.sf-exceptionreset .block { padding: 20px 25px; margin-bottom: 10px; border: 1px solid #ddd; background-color: #fff; text-align:left; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; width: 770px; box-shadow: 0 1px 2px rgba(0,0,0,0.15); -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.15); -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.3); } .sf-exceptionreset .traces { display: none; margin-top: 10px } -.sf-exceptionreset #message { margin-top: 30px; margin-bottom: 10px; padding: 20px 25px; text-align:left; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; min-width: 770px; max-width: 770px; background-color: #c8e8f3; border: 1px solid #ddd; background-image: -moz-linear-gradient(-90deg, #fff, #c8e8f3); background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#c8e8f3)); box-shadow: 0 1px 2px rgba(0,0,0,0.15); -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.15); -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.3); } +.sf-exceptionreset #message { margin-top: 30px; margin-bottom: 10px; padding: 20px 25px; text-align:left; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; width: 770px; background-color: #c8e8f3; border: 1px solid #ddd; background-image: -moz-linear-gradient(-90deg, #fff, #c8e8f3); background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#c8e8f3)); box-shadow: 0 1px 2px rgba(0,0,0,0.15); -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.15); -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.3); } .sf-exceptionreset #content { border: 1px solid #ddd; margin-top: 10px; padding: 7px; overflow: auto; } .sf-exceptionreset a.file_link { text-decoration: none; } .sf-exceptionreset a.file_link:hover { text-decoration: underline; } -.sf-exceptionreset .code { overflow: auto; } +.sf-exceptionreset code { font-size: 105%; font-family: monospace; overflow: auto; } .sf-exceptionreset img { vertical-align: middle; } .sf-exceptionreset .error { background-color: #f66 } .sf-exceptionreset .linked ul, .sf-exceptionreset .linked li { padding-left: 0; display: inline } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.php index eb32d7aa9bab..801668bcb930 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.php @@ -5,7 +5,7 @@
- +

get('code')->formatFileFromText(str_replace("\n", '
', htmlspecialchars($exception->getMessage(), ENT_QUOTES, $view->getCharset()))) ?>

diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.php index 1af24063e8aa..35911d5bfd77 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.php @@ -6,10 +6,12 @@ -
- get('slots')->get('_content') ?> -
+ get('slots')->get('_content') ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/logs.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/logs.php index 0b7ff93050c2..3b407fe45eb7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/logs.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/logs.php @@ -1,8 +1,8 @@ -
    +
      class="error"> : -
+ diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/trace.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/trace.php index 365646eb4200..4a24b11dfe9d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/trace.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/trace.php @@ -4,7 +4,7 @@ in get('code')->formatFile($trace['file'], $trace['line']) ?> »
-
    +
    get('code')->fileExcerpt($trace['file'], $trace['line']) ?> -
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.php index 0d9156819aee..16910538ab78 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.php @@ -10,11 +10,11 @@ -
    +
      getTrace() as $i => $trace): ?>
    1. render('FrameworkBundle:Exception:trace', array('prefix' => $position, 'i' => $i, 'trace' => $trace)) ?>
    2. -
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index 546c5b8787d0..9a8af499a1b5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -132,11 +132,14 @@ public function formatArgs($args) public function fileExcerpt($file, $line) { if (is_readable($file)) { - $content = preg_split('#
#', highlight_file($file, true)); + $code = highlight_file($file, true); + // remove main code/span tags + $code = preg_replace('#^\s*(.*)\s*#s', '\\1', $code); + $content = preg_split('#
#', $code); $lines = array(); for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; $i++) { - $lines[] = ''.$content[$i - 1].''; + $lines[] = ''.self::fixCodeMarkup($content[$i - 1]).''; } return '
    '.implode("\n", $lines).'
'; @@ -187,4 +190,23 @@ public function getName() { return 'code'; } + + protected static function fixCodeMarkup($line) + { + // ending tag from previous line + $opening = strpos($line, ''); + if (false !== $closing && (false === $opening || $closing < $opening)) { + $line = substr_replace($line, '', $closing, 7); + } + + // missing tag at the end of line + $opening = strpos($line, ''); + if (false !== $opening && (false === $closing || $closing > $opening)) { + $line .= ''; + } + + return $line; + } }