From 210d75be8e8678e4351b1494ac8779bd655afc65 Mon Sep 17 00:00:00 2001 From: Awen <39176130+yu1183688986@users.noreply.github.com> Date: Sun, 30 Jan 2022 21:45:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86@xss=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E5=AD=97=E6=AE=B5=E5=80=BC=E4=B8=BAnull=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82=E5=B8=B8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/common/xss/XssValidator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/xss/XssValidator.java b/ruoyi-common/src/main/java/com/ruoyi/common/xss/XssValidator.java index 43163721d..ce327e37e 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/xss/XssValidator.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/xss/XssValidator.java @@ -12,15 +12,18 @@ import java.util.regex.Pattern; */ public class XssValidator implements ConstraintValidator { - private final String HTML_PATTERN = "<(\\S*?)[^>]*>.*?|<.*? />"; + private static final String HTML_PATTERN = "<(\\S*?)[^>]*>.*?|<.*? />"; @Override public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { + if (StringUtils.isBlank(value)){ + return true; + } return !containsHtml(value); } - public boolean containsHtml(String value) + public static boolean containsHtml(String value) { Pattern pattern = Pattern.compile(HTML_PATTERN); Matcher matcher = pattern.matcher(value);