From 18997cdda7c15ec258e8aa3c9eb4e5a5e857bd50 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Mon, 23 Sep 2024 11:30:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E9=AB=98=E7=BA=A7=E6=90=9C=E7=B4=A2=E6=B2=A1=E6=9C=89=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=85=B3=E9=94=AE=E5=AD=97=E4=B8=AD=E7=9A=84=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1046882 --user=陈建星 【通用功能】筛选-输入文本框中输入反斜杠搜索不到结果 https://www.tapd.cn/55049933/s/1583260 --- .../java/io/metersphere/sdk/dto/BaseCondition.java | 10 +++++++++- .../system/interceptor/BaseConditionFilterAspect.java | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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()))