mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Added backwards compatibility to h()'s second param
This commit is contained in:
parent
b58899cf04
commit
137c4f7295
2 changed files with 28 additions and 1 deletions
|
@ -150,7 +150,11 @@ if (!function_exists('sortByKey')) {
|
||||||
*/
|
*/
|
||||||
function h($text, $double = true, $charset = null) {
|
function h($text, $double = true, $charset = null) {
|
||||||
if (is_array($text)) {
|
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;
|
static $defaultCharset = false;
|
||||||
|
@ -160,6 +164,9 @@ if (!function_exists('sortByKey')) {
|
||||||
$defaultCharset = 'UTF-8';
|
$defaultCharset = 'UTF-8';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (is_string($double)) {
|
||||||
|
$charset = $double;
|
||||||
|
}
|
||||||
if ($charset) {
|
if ($charset) {
|
||||||
return htmlspecialchars($text, ENT_QUOTES, $charset, $double);
|
return htmlspecialchars($text, ENT_QUOTES, $charset, $double);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -208,6 +208,26 @@ class BasicsTest extends CakeTestCase {
|
||||||
$string = '<foo> & ';
|
$string = '<foo> & ';
|
||||||
$result = h($string, false);
|
$result = h($string, false);
|
||||||
$this->assertEqual('<foo> & ', $result);
|
$this->assertEqual('<foo> & ', $result);
|
||||||
|
|
||||||
|
$string = '<foo> & ';
|
||||||
|
$result = h($string, 'UTF-8');
|
||||||
|
$this->assertEqual('<foo> & &nbsp;', $result);
|
||||||
|
|
||||||
|
$arr = array('<foo>', ' ');
|
||||||
|
$result = h($arr);
|
||||||
|
$expected = array(
|
||||||
|
'<foo>',
|
||||||
|
'&nbsp;'
|
||||||
|
);
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$arr = array('<foo>', ' ');
|
||||||
|
$result = h($arr, false);
|
||||||
|
$expected = array(
|
||||||
|
'<foo>',
|
||||||
|
' '
|
||||||
|
);
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue