From 38577ca1495bf8a0b5345bff1f7a12ac35f0b5af Mon Sep 17 00:00:00 2001 From: phpnut Date: Fri, 23 Mar 2007 06:36:24 +0000 Subject: [PATCH] Adding fix for #2219 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4654 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helper.php | 46 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index 9b69c3334..806febc70 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -255,29 +255,37 @@ class Helper extends Overloadable { * @return string */ function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) { - $minimizedAttributes = array('compact', 'checked', 'declare', 'readonly', 'disabled', 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize'); - if (!is_array($exclude)) { - $exclude = array(); - } - if (is_array($options)) { - $out = array(); - - foreach($options as $key => $value) { - if (!in_array($key, $exclude)) { - if (in_array($key, $minimizedAttributes) && ($value === 1 || $value === true || $value === 'true' || in_array($value, $minimizedAttributes))) { - $value = $key; - } elseif(in_array($key, $minimizedAttributes)) { - continue; - } - $out[] = "{$key}=\"{$value}\""; - } + if (!is_array($exclude)) { + $exclude = array(); } - $out = join(' ', $out); - return $out ? $insertBefore . $out . $insertAfter : null; + $keys = array_diff(array_keys($options), $exclude); + $values = array_intersect_key(array_values($options), $keys); + $out = implode(' ', array_map(array(&$this, '__formatAttribute'), $keys, $values)); } else { - return $options ? $insertBefore . $options . $insertAfter : null; + $out = $options; } + return $out ? $insertBefore . $out . $insertAfter : ''; + } +/** + * @param string $key + * @param string $value + * @return string + * @access private + */ + function __formatAttribute($key, $value) { + $attribute = ''; + $attributeFormat = '%s="%s"'; + $minimizedAttributes = array('compact', 'checked', 'declare', 'readonly', 'disabled', 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize'); + + if (in_array($key, $minimizedAttributes)) { + if ($value === 1 || $value === true || $value === 'true' || $value == $key) { + $attribute = sprintf($attributeFormat, $key, $key); + } + } else { + $attribute = sprintf($attributeFormat, $key, htmlspecialchars($value)); + } + return $attribute; } /** * @deprecated Name changed to '_parseAttributes'. Version 0.9.2.