mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-12 06:56:24 +00:00
Optimizing Sanitize::html() by caching default charset. Closes #496. Also charset passed in $options parameter now takes precedence over the default value obtained from app's config value 'App.encoding'
This commit is contained in:
parent
817ebf5ec8
commit
209af202ec
1 changed files with 14 additions and 10 deletions
|
@ -97,9 +97,16 @@ class Sanitize {
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function html($string, $options = array()) {
|
function html($string, $options = array()) {
|
||||||
|
static $defaultCharset = false;
|
||||||
|
if ($defaultCharset === false) {
|
||||||
|
$defaultCharset = Configure::read('App.encoding');
|
||||||
|
if ($defaultCharset === null) {
|
||||||
|
$defaultCharset = 'UTF-8';
|
||||||
|
}
|
||||||
|
}
|
||||||
$default = array(
|
$default = array(
|
||||||
'remove' => false,
|
'remove' => false,
|
||||||
'charset' => 'UTF-8',
|
'charset' => $defaultCharset,
|
||||||
'quotes' => ENT_QUOTES
|
'quotes' => ENT_QUOTES
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -108,11 +115,8 @@ class Sanitize {
|
||||||
if ($options['remove']) {
|
if ($options['remove']) {
|
||||||
$string = strip_tags($string);
|
$string = strip_tags($string);
|
||||||
}
|
}
|
||||||
$encoding = Configure::read('App.encoding');
|
|
||||||
if (empty($encoding)) {
|
return htmlentities($string, $options['quotes'], $options['charset']);
|
||||||
$encoding = $options['charset'];
|
|
||||||
}
|
|
||||||
return htmlentities($string, $options['quotes'], $encoding);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue