From 483d7124ddf0c8794f3999fbd68979a2435593bb Mon Sep 17 00:00:00 2001 From: Rachman Chavik Date: Mon, 28 May 2012 10:19:44 +0700 Subject: [PATCH] debug() may output path that is incorrectly truncated This happens when debug is called in core source files that resides in a different directory to the app. --- lib/Cake/Test/Case/BasicsTest.php | 23 ++++++++++++----------- lib/Cake/basics.php | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/Cake/Test/Case/BasicsTest.php b/lib/Cake/Test/Case/BasicsTest.php index 253122c3a..1bca6cb68 100644 --- a/lib/Cake/Test/Case/BasicsTest.php +++ b/lib/Cake/Test/Case/BasicsTest.php @@ -691,7 +691,8 @@ class BasicsTest extends CakeTestCase { 'this-is-a-test' ########################### EXPECTED; - $expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 8); + $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8); + $this->assertEquals($expected, $result); ob_start(); @@ -705,7 +706,7 @@ EXPECTED; EXPECTED; - $expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 10); + $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10); $this->assertEquals($expected, $result); ob_start(); @@ -719,7 +720,7 @@ EXPECTED; EXPECTED; - $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10); + $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10); $this->assertEquals($expected, $result); ob_start(); @@ -733,7 +734,7 @@ EXPECTED; EXPECTED; - $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10); + $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10); $this->assertEquals($expected, $result); ob_start(); @@ -754,9 +755,9 @@ EXPECTED; ########################### EXPECTED; if (php_sapi_name() == 'cli') { - $expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17); + $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17); } else { - $expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19); + $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19); } $this->assertEquals($expected, $result); @@ -778,9 +779,9 @@ EXPECTED; ########################### EXPECTED; if (php_sapi_name() == 'cli') { - $expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17); + $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17); } else { - $expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19); + $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19); } $this->assertEquals($expected, $result); @@ -793,7 +794,7 @@ EXPECTED; '
this-is-a-test
' ########################### EXPECTED; - $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8); + $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8); $this->assertEquals($expected, $result); ob_start(); @@ -805,7 +806,7 @@ EXPECTED; '
this-is-a-test
' ########################### EXPECTED; - $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8); + $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8); $this->assertEquals($expected, $result); ob_start(); @@ -817,7 +818,7 @@ EXPECTED; '
this-is-a-test
' ########################### EXPECTED; - $expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8); + $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8); $this->assertEquals($expected, $result); } diff --git a/lib/Cake/basics.php b/lib/Cake/basics.php index 694e1ab16..e2bc6e685 100644 --- a/lib/Cake/basics.php +++ b/lib/Cake/basics.php @@ -77,7 +77,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) { $lineInfo = ''; if ($showFrom) { $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array')); - $file = substr($trace[0]['file'], strlen(ROOT)); + $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']); $line = $trace[0]['line']; } $html = <<