| | |
| | | package com.ruoyi.common.xss;
|
| | |
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import javax.validation.ConstraintValidator;
|
| | | import javax.validation.ConstraintValidatorContext;
|
| | | import java.util.regex.Matcher;
|
| | |
| | | */
|
| | | public class XssValidator implements ConstraintValidator<Xss, String>
|
| | | {
|
| | | 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);
|