From 50236ae4e5e6009cfeefbbd48dce097b75222cd5 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 10 Feb 2022 17:17:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DXss=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=80=BC=E4=B8=BA=E7=A9=BA=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ruoyi/common/utils/poi/ExcelUtil.java | 1 - .../src/main/java/com/ruoyi/common/xss/XssValidator.java | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index 22b6b57..e8f2950 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -88,7 +88,6 @@ public class ExcelUtil public static final String[] FORMULA_STR = { "=", "-", "+", "@" }; - /** * Excel sheet最大行数,默认65536 */ 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 4316372..34d0700 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 @@ -1,5 +1,6 @@ package com.ruoyi.common.xss; +import com.ruoyi.common.utils.StringUtils; import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; import java.util.regex.Matcher; @@ -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);