From 1e49be3472b27fd7b67094eaab78cae84db3d893 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 8 Dec 2012 20:48:13 -0500 Subject: [PATCH] Fix stack traces not being highlighted correctly. Fixes #3439 --- lib/Cake/Test/Case/Utility/DebuggerTest.php | 8 +++++- lib/Cake/Utility/Debugger.php | 30 ++++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/DebuggerTest.php b/lib/Cake/Test/Case/Utility/DebuggerTest.php index 8040073c3..ea6912122 100644 --- a/lib/Cake/Test/Case/Utility/DebuggerTest.php +++ b/lib/Cake/Test/Case/Utility/DebuggerTest.php @@ -84,7 +84,13 @@ class DebuggerTest extends CakeTestCase { $this->assertTrue(is_array($result)); $this->assertEquals(4, count($result)); - $pattern = '/.*?<\?php/'; + $pattern = '/.*?.*?<\?php/'; + $this->assertRegExp($pattern, $result[0]); + + $result = Debugger::excerpt(__FILE__, 10, 2); + $this->assertEquals(5, count($result)); + + $pattern = '/\*<\/span>/'; $this->assertRegExp($pattern, $result[0]); $return = Debugger::excerpt('[internal]', 2, 2); diff --git a/lib/Cake/Utility/Debugger.php b/lib/Cake/Utility/Debugger.php index 0fe8a384b..0b7e1ebfd 100644 --- a/lib/Cake/Utility/Debugger.php +++ b/lib/Cake/Utility/Debugger.php @@ -396,12 +396,14 @@ class Debugger { return array(); } $data = file_get_contents($file); - if (!empty($data) && strpos($data, "\n") !== false) { + if (empty($data)) { + return $lines; + } + if (strpos($data, "\n") !== false) { $data = explode("\n", $data); } - - if (empty($data) || !isset($data[$line])) { - return; + if (!isset($data[$line])) { + return $lines; } for ($i = $line - ($context + 1); $i < $line + $context; $i++) { if (!isset($data[$i])) { @@ -425,13 +427,23 @@ class Debugger { * @return string */ protected static function _highlight($str) { - static $supportHighlight = null; - if (!$supportHighlight && function_exists('hphp_log')) { - $supportHighlight = false; + if (function_exists('hphp_log')) { return htmlentities($str); } - $supportHighlight = true; - return highlight_string($str, true); + $added = false; + if (strpos($str, '', + '', + $highlight + ); + } + return $highlight; } /**