Skip to content

Commit

Permalink
Made debug() output html-safe strings by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
predominant committed Dec 10, 2010
1 parent 33d2f9a commit e9907cb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cake/basics.php
Expand Up @@ -85,12 +85,12 @@ function uses() {
* Only runs if debug level is greater than zero. * Only runs if debug level is greater than zero.
* *
* @param boolean $var Variable to show debug information for. * @param boolean $var Variable to show debug information for.
* @param boolean $showHtml If set to true, the method prints the debug data in a screen-friendly way. * @param boolean $showHtml If set to true, the method prints the debug data in a browser-friendly way.
* @param boolean $showFrom If set to true, the method prints from where the function was called. * @param boolean $showFrom If set to true, the method prints from where the function was called.
* @link http://book.cakephp.org/view/1190/Basic-Debugging * @link http://book.cakephp.org/view/1190/Basic-Debugging
* @link http://book.cakephp.org/view/1128/debug * @link http://book.cakephp.org/view/1128/debug
*/ */
function debug($var = false, $showHtml = false, $showFrom = true) { function debug($var = false, $showHtml = null, $showFrom = true) {
if (Configure::read('debug') > 0) { if (Configure::read('debug') > 0) {
$file = ''; $file = '';
$line = ''; $line = '';
Expand All @@ -116,10 +116,14 @@ function debug($var = false, $showHtml = false, $showFrom = true) {
$template = $html; $template = $html;
if (php_sapi_name() == 'cli') { if (php_sapi_name() == 'cli') {
$template = $text; $template = $text;
} else {
if ($showHtml === null) {
$showHtml = true;
}
} }
$var = print_r($var, true); $var = print_r($var, true);
if ($showHtml) { if ($showHtml) {
$var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var)); $var = str_replace(array('<', '>'), array('&lt;', '&gt;'), $var);
} }
printf($template, $file, $line, $var); printf($template, $file, $line, $var);
} }
Expand Down

0 comments on commit e9907cb

Please sign in to comment.