Skip to content

Commit

Permalink
Added 'double' option to Santize::html() to pass double_encode parame…
Browse files Browse the repository at this point in the history
…ter to htmlentities()
  • Loading branch information
jeremyharris committed Oct 12, 2010
1 parent c686362 commit b58899c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cake/libs/sanitize.php
Expand Up @@ -85,6 +85,7 @@ public static function escape($string, $connection = 'default') {
* - 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.
Expand All @@ -101,7 +102,8 @@ public static function html($string, $options = array()) {
$default = array(
'remove' => false,
'charset' => $defaultCharset,
'quotes' => ENT_QUOTES
'quotes' => ENT_QUOTES,
'double' => true
);

$options = array_merge($default, $options);
Expand All @@ -110,7 +112,7 @@ public static function html($string, $options = array()) {
$string = strip_tags($string);
}

return htmlentities($string, $options['quotes'], $options['charset']);
return htmlentities($string, $options['quotes'], $options['charset'], $options['double']);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions cake/tests/cases/libs/sanitize.test.php
Expand Up @@ -236,6 +236,16 @@ function testHtml() {
$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);
}

/**
Expand Down

0 comments on commit b58899c

Please sign in to comment.