summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodneyrehm <rodneyrehm@localhost>2011-10-05 18:51:10 +0000
committerrodneyrehm <rodneyrehm@localhost>2011-10-05 18:51:10 +0000
commit3825ef336c2f26d2e4998b68892430e402036574 (patch)
treea6745792ebf54682dc82b22d1318cdba9d8256ad
parent1e48394ed325584c8a522de1a09e462f8edfbbe1 (diff)
downloadsmarty-3825ef336c2f26d2e4998b68892430e402036574.tar.gz
smarty-3825ef336c2f26d2e4998b68892430e402036574.tar.bz2
smarty-3825ef336c2f26d2e4998b68892430e402036574.zip
- bugfix html_options plugin did not handle null- and object values properly (Issue #49, Forum Topic 20049)
-rw-r--r--change_log.txt1
-rw-r--r--libs/plugins/function.html_options.php35
2 files changed, 29 insertions, 7 deletions
diff --git a/change_log.txt b/change_log.txt
index d9cd5910..83b63a2a 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -3,6 +3,7 @@
- bugfix of problem introduced with r4342 by replacing strlen() with isset()
- add environment configuration issue with mbstring.func_overload Smarty cannot compensate for (Issue #45)
- bugfix nofilter tag option did not disable default modifier
+- bugfix html_options plugin did not handle null- and object values properly (Issue #49, Forum Topic 20049)
04.10.2011
- bugfix assign() in plugins called in subtemplates did change value also in parent template
diff --git a/libs/plugins/function.html_options.php b/libs/plugins/function.html_options.php
index 9c524b92..80a9e029 100644
--- a/libs/plugins/function.html_options.php
+++ b/libs/plugins/function.html_options.php
@@ -66,9 +66,28 @@ function smarty_function_html_options($params, $template)
case 'selected':
if (is_array($_val)) {
- $selected = array_flip(array_map('strval', array_values((array)$_val)));
+ $selected = array();
+ foreach ($_val as $_sel) {
+ if (is_object($_sel)) {
+ if (method_exists($_sel, "__toString")) {
+ $selected = smarty_function_escape_special_chars((string) $_sel->__toString());
+ } else {
+ trigger_error("html_options: selected attribute contains an object of class '". get_class($_sel) ."' without __toString() method", E_USER_NOTICE);
+ continue;
+ }
+ } else {
+ $_sel = smarty_function_escape_special_chars((string) $_sel);
+ }
+ $selected[$_sel] = true;
+ }
+ } elseif (is_object($_val)) {
+ if (method_exists($_val, "__toString")) {
+ $selected = smarty_function_escape_special_chars((string) $_val->__toString());
+ } else {
+ trigger_error("html_options: selected attribute is an object of class '". get_class($_val) ."' without __toString() method", E_USER_NOTICE);
+ }
} else {
- $selected = $_val;
+ $selected = smarty_function_escape_special_chars((string) $_val);
}
break;
@@ -82,9 +101,10 @@ function smarty_function_html_options($params, $template)
}
}
- if (!isset($options) && !isset($values))
+ if (!isset($options) && !isset($values)) {
+ /* raise error here? */
return '';
- /* raise error here? */
+ }
$_html_result = '';
$_idx = 0;
@@ -112,12 +132,13 @@ function smarty_function_html_options($params, $template)
function smarty_function_html_options_optoutput($key, $value, $selected, $id, $class, &$idx)
{
if (!is_array($value)) {
- $_html_result = '<option value="' . smarty_function_escape_special_chars($key) . '"';
+ $_key = smarty_function_escape_special_chars($key);
+ $_html_result = '<option value="' . $_key . '"';
if (is_array($selected)) {
- if (isset($selected[(string) $key])) {
+ if (isset($selected[$_key])) {
$_html_result .= ' selected="selected"';
}
- } elseif ($key == $selected) {
+ } elseif ($_key === $selected) {
$_html_result .= ' selected="selected"';
}
$_html_class = !empty($class) ? ' class="'.$class.' option"' : '';