diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BaseCondition.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BaseCondition.java index 30de830e37..7c1dba9b5a 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BaseCondition.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/BaseCondition.java @@ -29,7 +29,15 @@ public class BaseCondition { private Map combine; // 转JSON时会调用。 前台数据传过来时可以顺便处理掉转义字符 + @Deprecated public void setKeyword(String keyword) { + this.keyword = transferKeyword(keyword); + } + + public static String transferKeyword(String keyword) { + if (StringUtils.contains(keyword, "\\") && !StringUtils.contains(keyword, "\\\\")) { + keyword = StringUtils.replace(keyword, "\\", "\\\\"); + } //判断之前有没有转义过。转义过就不再转义。耍花活的自己想办法解决 if (StringUtils.contains(keyword, "%") && !StringUtils.contains(keyword, "\\%")) { keyword = StringUtils.replace(keyword, "%", "\\%"); @@ -37,7 +45,7 @@ public class BaseCondition { if (StringUtils.contains(keyword, "_") && !StringUtils.contains(keyword, "\\_")) { keyword = StringUtils.replace(keyword, "_", "\\_"); } - this.keyword = keyword; + return keyword; } public void initKeyword(String keyword) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/interceptor/BaseConditionFilterAspect.java b/backend/services/system-setting/src/main/java/io/metersphere/system/interceptor/BaseConditionFilterAspect.java index 6079220744..f1d3d5ccb0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/interceptor/BaseConditionFilterAspect.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/interceptor/BaseConditionFilterAspect.java @@ -65,6 +65,12 @@ public class BaseConditionFilterAspect { return; } List validConditions = getValidConditions(combineSearch.getConditions()); + validConditions.forEach(item -> { + if (item.getValue() != null && item.getValue() instanceof String strValue) { + // 转义 mysql 的特殊字符 + item.setValue(BaseCondition.transferKeyword(strValue)); + } + }); replaceCurrentUser(validConditions); List systemFieldConditions = validConditions.stream() .filter(item -> !BooleanUtils.isTrue(item.getCustomField()))