removed '\r' from debug_print_vars' output

properly escape vars in javascript-version of debug.tpl
This commit is contained in:
messju
2003-08-13 14:15:30 +00:00
parent 3ffab5a3ab
commit ab839a5b13
2 changed files with 6 additions and 7 deletions

View File

@@ -47,13 +47,13 @@
{/section}
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>assigned template variables:</b></td></tr>");
{section name=vars loop=$_debug_keys}
_smarty_console.document.write("<tr bgcolor={if %vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color=green>{$_debug_vals[vars]|@debug_print_var}</font></tt></td></tr>");
_smarty_console.document.write("<tr bgcolor={if %vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=blue>{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color=green>{$_debug_vals[vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>");
{sectionelse}
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no template variables assigned</i></tt></td></tr>");
{/section}
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>assigned config file variables (outer template scope):</b></td></tr>");
{section name=config_vars loop=$_debug_config_keys}
_smarty_console.document.write("<tr bgcolor={if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color=green>{$_debug_config_vals[config_vars]|@debug_print_var}</font></tt></td></tr>");
_smarty_console.document.write("<tr bgcolor={if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}><td valign=top><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color=green>{$_debug_config_vals[config_vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>");
{sectionelse}
_smarty_console.document.write("<tr bgcolor=#eeeeee><td colspan=2><tt><i>no config vars assigned</i></tt></td></tr>");
{/section}

View File

@@ -21,13 +21,12 @@
*/
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
{
$_search = array("!\n!", "!\r!", "!\t!");
$_replace = array('<i>&#92;n</i>', '<i>&#92;r</i>', '<i>&#92;t</i>');
$_replace = array("\n"=>'<i>&#92;n</i>', "\r"=>'<i>&#92;r</i>', "\t"=>'<i>&#92;t</i>');
if (is_array($var)) {
$results = "<b>Array (".count($var).")</b>";
foreach ($var as $curr_key => $curr_val) {
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
$results .= '<br>\r'.str_repeat('&nbsp;', $depth*2)."<b>".preg_replace($_search, $_replace, $curr_key)."</b> =&gt; $return";
$results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> =&gt; $return";
}
return $results;
} else if (is_object($var)) {
@@ -35,7 +34,7 @@ function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
$results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
foreach ($object_vars as $curr_key => $curr_val) {
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
$results .= '<br>\r'.str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return";
$results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return";
}
return $results;
} else {
@@ -48,7 +47,7 @@ function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
$results = $var;
}
$results = htmlspecialchars($results);
$results = preg_replace($_search, $_replace, $results);
$results = strtr($results, $_replace);
return $results;
}
}