diff --git a/cake/basics.php b/cake/basics.php index 2da3b80c0..ca262cb0a 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -150,7 +150,11 @@ if (!function_exists('sortByKey')) { */ function h($text, $double = true, $charset = null) { if (is_array($text)) { - return array_map('h', $text); + $texts = array(); + foreach ($text as $t) { + $texts[] = h($t, $double, $charset); + } + return $texts; } static $defaultCharset = false; @@ -160,6 +164,9 @@ if (!function_exists('sortByKey')) { $defaultCharset = 'UTF-8'; } } + if (is_string($double)) { + $charset = $double; + } if ($charset) { return htmlspecialchars($text, ENT_QUOTES, $charset, $double); } else { diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index 12fe82f02..8df308ba9 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -208,6 +208,26 @@ class BasicsTest extends CakeTestCase { $string = ' &  '; $result = h($string, false); $this->assertEqual('<foo> &  ', $result); + + $string = ' &  '; + $result = h($string, 'UTF-8'); + $this->assertEqual('<foo> & &nbsp;', $result); + + $arr = array('', ' '); + $result = h($arr); + $expected = array( + '<foo>', + '&nbsp;' + ); + $this->assertEqual($expected, $result); + + $arr = array('', ' '); + $result = h($arr, false); + $expected = array( + '<foo>', + ' ' + ); + $this->assertEqual($expected, $result); } /**