add appropriate warnings when passing array as extra parameter

This commit is contained in:
mohrt
2003-04-14 16:57:40 +00:00
parent 7221c8afee
commit 423c1a2eae
5 changed files with 43 additions and 25 deletions

View File

@@ -67,7 +67,11 @@ function smarty_function_html_checkboxes($params, &$smarty)
break; break;
default: default:
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars((string)$_val).'"'; if(!is_array($_val)) {
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} else {
$smarty->trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break; break;
} }
} }

View File

@@ -63,7 +63,11 @@ function smarty_function_html_image($params, &$smarty)
$dpi = $_val; $dpi = $_val;
break; break;
default: default:
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; if(!is_array($_val)) {
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} else {
$smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break; break;
} }
} }

View File

@@ -26,27 +26,31 @@ function smarty_function_html_options($params, &$smarty)
$extra = ''; $extra = '';
foreach($params as $_key => $_val) { foreach($params as $_key => $_val) {
switch($_key) { switch($_key) {
case 'name': case 'name':
$$_key = (string)$_val; $$_key = (string)$_val;
break; break;
case 'options': case 'options':
$$_key = (array)$_val; $$_key = (array)$_val;
break; break;
case 'selected': case 'selected':
case 'values': case 'values':
case 'output': case 'output':
$$_key = array_values((array)$_val); $$_key = array_values((array)$_val);
break; break;
default: default:
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; if(!is_array($_val)) {
break; $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} } else {
} $smarty->trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if (!isset($options) && !isset($values)) if (!isset($options) && !isset($values))
return ''; /* raise error here? */ return ''; /* raise error here? */

View File

@@ -71,7 +71,11 @@ function smarty_function_html_radios($params, &$smarty)
default: default:
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars((string)$_val).'"'; if(!is_array($_val)) {
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} else {
$smarty->trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break; break;
} }
} }

View File

@@ -7,9 +7,11 @@
\*======================================================================*/ \*======================================================================*/
function smarty_function_escape_special_chars($string) function smarty_function_escape_special_chars($string)
{ {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); if(!is_array($string)) {
$string = htmlspecialchars($string); $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = str_replace(array('%%%SMARTY_START%%%','%%%SMARTY_END%%%'), array('&',';'), $string); $string = htmlspecialchars($string);
$string = str_replace(array('%%%SMARTY_START%%%','%%%SMARTY_END%%%'), array('&',';'), $string);
}
return $string; return $string;
} }