Added 'double' option to Santize::html() to pass double_encode parameter to htmlentities()

This commit is contained in:
Jeremy Harris 2010-10-11 18:25:11 -07:00
parent c686362de8
commit b58899cf04
2 changed files with 14 additions and 2 deletions

View file

@ -85,6 +85,7 @@ class Sanitize {
* - remove (boolean) if true strips all HTML tags before encoding
* - charset (string) the charset used to encode the string
* - quotes (int) see http://php.net/manual/en/function.htmlentities.php
* - double (boolean) doube encode html entities
*
* @param string $string String from where to strip tags
* @param array $options Array of options to use.
@ -101,7 +102,8 @@ class Sanitize {
$default = array(
'remove' => false,
'charset' => $defaultCharset,
'quotes' => ENT_QUOTES
'quotes' => ENT_QUOTES,
'double' => true
);
$options = array_merge($default, $options);
@ -110,7 +112,7 @@ class Sanitize {
$string = strip_tags($string);
}
return htmlentities($string, $options['quotes'], $options['charset']);
return htmlentities($string, $options['quotes'], $options['charset'], $options['double']);
}
/**

View file

@ -236,6 +236,16 @@ class SanitizeTest extends CakeTestCase {
$expected = 'The "lazy" dog 'jumped' & flew over the moon. If (1+1) = 2 <em>is</em> true, (2-1) = 1 is also true';
$result = Sanitize::html($string);
$this->assertEqual($result, $expected);
$string = 'The "lazy" dog & his friend Apple® conquered the world';
$expected = 'The "lazy" dog & his friend Apple® conquered the world';
$result = Sanitize::html($string);
$this->assertEqual($result, $expected);
$string = 'The "lazy" dog & his friend Apple® conquered the world';
$expected = 'The "lazy" dog & his friend Apple® conquered the world';
$result = Sanitize::html($string, array('double' => false));
$this->assertEqual($result, $expected);
}
/**