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 = '