Skip to content
Permalink
Browse files

Added backwards compatibility to h()'s second param

  • Loading branch information...
jeremyharris committed Oct 12, 2010
1 parent b58899c commit 137c4f72956a9a6cb908bce3a8ad3f9be3316096
Showing with 28 additions and 1 deletion.
  1. +8 −1 cake/basics.php
  2. +20 −0 cake/tests/cases/basics.test.php
@@ -150,7 +150,11 @@ function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
*/
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 @@ function h($text, $double = true, $charset = null) {
$defaultCharset = 'UTF-8';
}
}
if (is_string($double)) {
$charset = $double;
}
if ($charset) {
return htmlspecialchars($text, ENT_QUOTES, $charset, $double);
} else {
@@ -208,6 +208,26 @@ public function testH() {
$string = '<foo> & &nbsp;';
$result = h($string, false);
$this->assertEqual('&lt;foo&gt; &amp; &nbsp;', $result);
$string = '<foo> & &nbsp;';
$result = h($string, 'UTF-8');
$this->assertEqual('&lt;foo&gt; &amp; &amp;nbsp;', $result);
$arr = array('<foo>', '&nbsp;');
$result = h($arr);
$expected = array(
'&lt;foo&gt;',
'&amp;nbsp;'
);
$this->assertEqual($expected, $result);
$arr = array('<foo>', '&nbsp;');
$result = h($arr, false);
$expected = array(
'&lt;foo&gt;',
'&nbsp;'
);
$this->assertEqual($expected, $result);
}
/**

0 comments on commit 137c4f7

Please sign in to comment.
You can’t perform that action at this time.