From accfb22cbbf4dc3315b99d2c999b9dda7b7825ca Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 15 Jul 2021 10:00:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8DIF=E6=9D=A1=E4=BB=B6=E4=B8=8B${?= =?UTF-8?q?value}=20value=20=E5=8C=85=E5=90=AB=E5=BC=95=E5=8F=B7=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20#1005122=20--bug=3D1005127=20--user=3D=E8=B5=B5?= =?UTF-8?q?=E5=8B=87=20=E3=80=90github#4631=E3=80=91=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=B7=9F...=20https://www.tapd.cn/55049933/s/1025395?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/controller/MsIfController.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsIfController.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsIfController.java index 4ebadabe5d..9cdfd39e4b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsIfController.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsIfController.java @@ -13,6 +13,8 @@ import org.apache.jmeter.testelement.TestElement; import org.apache.jorphan.collections.HashTree; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Data @EqualsAndHashCode(callSuper = true) @@ -74,8 +76,26 @@ public class MsIfController extends MsTestElement { return "IfController"; } + public String getContentValue() { + String content = this.variable; + Pattern regex = Pattern.compile("\\$\\{([^}]*)\\}"); + Matcher matcher = regex.matcher(content); + StringBuilder stringBuilder = new StringBuilder(); + while (matcher.find()) { + stringBuilder.append(matcher.group(1) + ","); + } + if (stringBuilder.length() > 0) { + stringBuilder.deleteCharAt(stringBuilder.length() - 1); + } + if (StringUtils.isEmpty(stringBuilder.toString())) { + return this.variable; + } + return stringBuilder.toString(); + } + public String getCondition() { - String variable = "\"" + this.variable + "\""; + String key = getContentValue(); + String variable = key.equals(this.variable) ? "\"" + this.variable + "\"" : "vars.get('" + key + "')"; String operator = this.operator; String value; if (StringUtils.equals(operator, "<") || StringUtils.equals(operator, ">")) {