Skip to content
Permalink
Browse files

Added double_encode paramater to h()

  • Loading branch information...
jeremyharris committed Oct 12, 2010
1 parent 5c025d0 commit c686362de8c04302a6bb897cbce26f8afbef1600
Showing with 12 additions and 3 deletions.
  1. +4 −3 cake/basics.php
  2. +8 −0 cake/tests/cases/basics.test.php
@@ -143,11 +143,12 @@ function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
* Convenience method for 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'
* @return string Wrapped text
* @link http://book.cakephp.org/view/1132/h
*/
function h($text, $charset = null) {
function h($text, $double = true, $charset = null) {
if (is_array($text)) {
return array_map('h', $text);
}
@@ -160,9 +161,9 @@ function h($text, $charset = null) {
}
}
if ($charset) {
return htmlspecialchars($text, ENT_QUOTES, $charset);
return htmlspecialchars($text, ENT_QUOTES, $charset, $double);
} else {
return htmlspecialchars($text, ENT_QUOTES, $defaultCharset);
return htmlspecialchars($text, ENT_QUOTES, $defaultCharset, $double);
}
}
@@ -200,6 +200,14 @@ public function testH() {
$result = h($in);
$expected = array('this & that', '<p>Which one</p>');
$this->assertEqual($expected, $result);
$string = '<foo> & &nbsp;';
$result = h($string);
$this->assertEqual('&lt;foo&gt; &amp; &amp;nbsp;', $result);
$string = '<foo> & &nbsp;';
$result = h($string, false);
$this->assertEqual('&lt;foo&gt; &amp; &nbsp;', $result);
}
/**

0 comments on commit c686362

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