*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace HtmlSanitizer\Sanitizer;
/**
* @internal
*/
trait StringSanitizerTrait
{
private static $replacements = [
// """ is shorter than """
'"' => '"',
// Fix several potential issues in how browsers intepret attributes values
'+' => '+',
'=' => '=',
'@' => '@',
'`' => '`',
// Some DB engines will transform UTF8 full-width characters their classical version
// if the data is saved in a non-UTF8 field
'<' => '<',
'>' => '>',
'+' => '+',
'=' => '=',
'@' => '@',
'`' => '`',
];
public function encodeHtmlEntities(string $string): string
{
$string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$string = str_replace(array_keys(self::$replacements), array_values(self::$replacements), $string);
return $string;
}
}