浏览代码

优化匹配方式

RuoYi 1 年之前
父节点
当前提交
649cfe8652
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      ruoyi-common/src/main/java/com/ruoyi/common/xss/XssValidator.java

+ 6 - 1
ruoyi-common/src/main/java/com/ruoyi/common/xss/XssValidator.java

@@ -27,8 +27,13 @@ public class XssValidator implements ConstraintValidator<Xss, String>
 
     public static boolean containsHtml(String value)
     {
+        StringBuilder sHtml = new StringBuilder();
         Pattern pattern = Pattern.compile(HTML_PATTERN);
         Matcher matcher = pattern.matcher(value);
-        return matcher.matches();
+        while (matcher.find())
+        {
+            sHtml.append(matcher.group());
+        }
+        return pattern.matcher(sHtml).matches();
     }
 }