mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Added double_encode paramater to h()
This commit is contained in:
parent
5c025d0a18
commit
c686362de8
2 changed files with 12 additions and 3 deletions
|
@ -143,11 +143,12 @@ if (!function_exists('sortByKey')) {
|
||||||
* Convenience method for htmlspecialchars.
|
* Convenience method for htmlspecialchars.
|
||||||
*
|
*
|
||||||
* @param string $text Text to wrap through htmlspecialchars
|
* @param string $text Text to wrap through htmlspecialchars
|
||||||
|
* @param boolean $double Encode existing html entities
|
||||||
* @param string $charset Character set to use when escaping. Defaults to config value in 'App.encoding' or 'UTF-8'
|
* @param string $charset Character set to use when escaping. Defaults to config value in 'App.encoding' or 'UTF-8'
|
||||||
* @return string Wrapped text
|
* @return string Wrapped text
|
||||||
* @link http://book.cakephp.org/view/1132/h
|
* @link http://book.cakephp.org/view/1132/h
|
||||||
*/
|
*/
|
||||||
function h($text, $charset = null) {
|
function h($text, $double = true, $charset = null) {
|
||||||
if (is_array($text)) {
|
if (is_array($text)) {
|
||||||
return array_map('h', $text);
|
return array_map('h', $text);
|
||||||
}
|
}
|
||||||
|
@ -160,9 +161,9 @@ if (!function_exists('sortByKey')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($charset) {
|
if ($charset) {
|
||||||
return htmlspecialchars($text, ENT_QUOTES, $charset);
|
return htmlspecialchars($text, ENT_QUOTES, $charset, $double);
|
||||||
} else {
|
} else {
|
||||||
return htmlspecialchars($text, ENT_QUOTES, $defaultCharset);
|
return htmlspecialchars($text, ENT_QUOTES, $defaultCharset, $double);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,14 @@ class BasicsTest extends CakeTestCase {
|
||||||
$result = h($in);
|
$result = h($in);
|
||||||
$expected = array('this & that', '<p>Which one</p>');
|
$expected = array('this & that', '<p>Which one</p>');
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$string = '<foo> & ';
|
||||||
|
$result = h($string);
|
||||||
|
$this->assertEqual('<foo> & &nbsp;', $result);
|
||||||
|
|
||||||
|
$string = '<foo> & ';
|
||||||
|
$result = h($string, false);
|
||||||
|
$this->assertEqual('<foo> & ', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue