From 137c4f72956a9a6cb908bce3a8ad3f9be3316096 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Mon, 11 Oct 2010 19:26:41 -0700 Subject: [PATCH] Added backwards compatibility to h()'s second param --- cake/basics.php | 9 ++++++++- cake/tests/cases/basics.test.php | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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); } /**