Browse Source

!367 修复了@xss注解字段值为null时的空指针异常问题

Merge pull request !367 from 清溪先生/master
pull/368/head
清溪先生 3 years ago committed by Gitee
parent
commit
eb0602033d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
  1. 7
      ruoyi-common/src/main/java/com/ruoyi/common/xss/XssValidator.java

7
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<Xss, String> public class XssValidator implements ConstraintValidator<Xss, String>
{ {
private final String HTML_PATTERN = "<(\\S*?)[^>]*>.*?|<.*? />"; private static final String HTML_PATTERN = "<(\\S*?)[^>]*>.*?|<.*? />";
@Override @Override
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext)
{ {
if (StringUtils.isBlank(value)){
return true;
}
return !containsHtml(value); return !containsHtml(value);
} }
public boolean containsHtml(String value) public static boolean containsHtml(String value)
{ {
Pattern pattern = Pattern.compile(HTML_PATTERN); Pattern pattern = Pattern.compile(HTML_PATTERN);
Matcher matcher = pattern.matcher(value); Matcher matcher = pattern.matcher(value);

Loading…
Cancel
Save