diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/xss/XssValidator.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/xss/XssValidator.java index c7dfde9..92405c2 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/xss/XssValidator.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/xss/XssValidator.java @@ -1,9 +1,10 @@ package com.ruoyi.common.core.xss; -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import com.ruoyi.common.core.utils.StringUtils; /** * 自定义xss校验注解实现 @@ -12,15 +13,19 @@ 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);