mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
feat:新增 clean_xss 的公共函数
This commit is contained in:
parent
9da48bb766
commit
5b03f2bcbb
@ -8,6 +8,7 @@ use think\facade\Db;
|
||||
use think\facade\Lang;
|
||||
use think\facade\Event;
|
||||
use think\facade\Config;
|
||||
use voku\helper\AntiXSS;
|
||||
use app\admin\model\Config as configModel;
|
||||
use think\exception\HttpResponseException;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
@ -34,7 +35,7 @@ if (!function_exists('filter')) {
|
||||
|
||||
/**
|
||||
* 输入过滤
|
||||
* 富文本反XSS请使用(new AntiXSS())->xss_clean()
|
||||
* 富文本反XSS请使用 clean_xss,也就不需要及不能再 filter 了
|
||||
* @param string $string 要过滤的字符串
|
||||
* @return string
|
||||
*/
|
||||
@ -51,6 +52,22 @@ if (!function_exists('filter')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('clean_xss')) {
|
||||
|
||||
/**
|
||||
* 清理XSS
|
||||
* 通常只用于富文本,比 filter 慢
|
||||
* @param string $string
|
||||
* @param bool $htmlspecialchars
|
||||
* @return string
|
||||
*/
|
||||
function clean_xss(string $string, bool $htmlspecialchars = true): string
|
||||
{
|
||||
$string = (new AntiXSS())->xss_clean($string);
|
||||
return $htmlspecialchars ? htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8') : $string;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_sys_config')) {
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user