fix(接口测试): 正则断言失效

--bug=1039800 --user=陈建星 【接口测试】断言-变量,正则匹配断言错误 https://www.tapd.cn/55049933/s/1503523
This commit is contained in:
AgAngle 2024-04-21 17:26:41 +08:00 committed by Craftsman
parent c1a2eeb752
commit 2aef4d50b9
3 changed files with 4 additions and 4 deletions

View File

@ -55,7 +55,7 @@ public class KeyValueInfo {
} }
} else if (StringUtils.equals(this.condition, ParamConditionEnums.REGULAR_MATCH.name())) { } else if (StringUtils.equals(this.condition, ParamConditionEnums.REGULAR_MATCH.name())) {
try { try {
return this.value.matches(Pattern.quote(value)); return this.value.matches(value);
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }

View File

@ -61,8 +61,8 @@ public class ResponseHeaderAssertionConverter extends AssertionConverter<MsRespo
String testString = expectedValue; String testString = expectedValue;
if (StringUtils.isNotEmpty(regexTemplate)) { if (StringUtils.isNotEmpty(regexTemplate)) {
testString = regexTemplate testString = regexTemplate
.replace("%key", Pattern.quote(header)) .replace("%key", header)
.replace("%value", Pattern.quote(expectedValue)); .replace("%value", expectedValue);
} }
if (StringUtils.startsWith(msAssertionCondition.name(), "NOT")) { if (StringUtils.startsWith(msAssertionCondition.name(), "NOT")) {

View File

@ -82,7 +82,7 @@ public class VariableAssertionConverter extends AssertionConverter<MsVariableAss
""" """
import java.util.regex.Pattern; import java.util.regex.Pattern;
if (variableValue != null) { if (variableValue != null) {
result = Pattern.matches(Pattern.quote(expectation), variableValue); result = Pattern.matches(expectation, variableValue);
} else { } else {
result = false; result = false;
} }