diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index b34962cb0..ef4bd79d0 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -779,7 +779,20 @@ class WebSocketDialogMsg extends AbstractModel } // 过滤标签 $text = strip_tags($text, '
'); - $text = preg_replace("/\<(blockquote|strong|pre|ol|ul|li|em|p|s|u).*?\>/is", "<$1>", $text); // 不用去除a标签,上面已经处理过了 + $text = preg_replace_callback("/\<(blockquote|strong|pre|ol|ul|li|em|p|s|u)(.*?)\>/is", function (array $match) { // 不用去除a标签,上面已经处理过了 + preg_match("/<[^>]*?style=([\"'])(.*?)\\1[^>]*?>/is", $match[0], $matchs); + $attach = ''; + if ($matchs) { + $styleArray = explode(';', $matchs[2]); + $validStyles = array_filter($styleArray, function ($styleItem) { + return preg_match('/\s*(?:color|font-size|background-color|font-weight|font-family|text-decoration|font-style)\s*:/i', $styleItem); // 只保留指定样式 + }); + if ($validStyles) { + $attach = ' style="' . implode(';', $validStyles) . '"'; + } + } + return "<{$match[1]}{$attach}>"; + }, $text); $text = preg_replace_callback("/\[:LINK:(.*?):(.*?):\]/i", function (array $match) { return "" . base64_decode($match[2]) . ""; }, $text);