fix(接口测试): 修复正则的快捷提取当正则表达式不合法时会影响到页面显示的问题
--bug=1037759 --user=宋天阳 https://www.tapd.cn/55049933/s/1490276
This commit is contained in:
parent
19b0bf4251
commit
7e2dcb7b6c
|
@ -18,7 +18,7 @@ export const ExecuteScenarioUrl = '/api/scenario/run'; // 接口场景执行(
|
|||
export const GetSystemRequestUrl = '/api/scenario/get/system-request'; // 获取导入的系统请求数据
|
||||
export const FollowScenarioUrl = '/api/scenario/follow'; // 关注/取消关注接口场景
|
||||
export const ScenarioScheduleConfigUrl = '/api/scenario/schedule-config'; // 场景定时任务
|
||||
export const ScenarioScheduleConfigDeleteUrl = '/api/scenario/schedule-config-delete/'; // 场景定时任务
|
||||
export const ScenarioScheduleConfigDeleteUrl = '/api/scenario/schedule-config-delete'; // 场景定时任务
|
||||
export const GetStepProjectInfoUrl = '/api/scenario/step/project-ifo'; // 获取跨项目信息
|
||||
export const BatchRecycleScenarioUrl = '/api/scenario/batch-operation/delete-gc'; // 批量删除接口场景
|
||||
export const BatchMoveScenarioUrl = '/api/scenario/batch-operation/move'; // 批量移动接口场景
|
||||
|
|
|
@ -247,25 +247,31 @@
|
|||
break;
|
||||
case RequestExtractExpressionEnum.REGEX:
|
||||
default:
|
||||
// 先把前后的/和g去掉才能生成正则表达式
|
||||
const matchesIterator = props.response?.matchAll(
|
||||
new RegExp(expressionForm.value.expression.replace(/^\/|\/$|\/g$/g, ''), 'g')
|
||||
);
|
||||
if (matchesIterator) {
|
||||
const matches = Array.from(matchesIterator);
|
||||
try {
|
||||
if (expressionForm.value.expressionMatchingRule === 'EXPRESSION') {
|
||||
// 匹配表达式,取第一个匹配结果,是完整匹配结果
|
||||
matchResult.value = matches.map((e) => e[0]) || [];
|
||||
} else {
|
||||
matchResult.value = matches.map((e) => e.slice(1)).flat(Infinity) || []; // 匹配分组,取匹配结果的第二项开始,是分组匹配结果
|
||||
// 正则匹配中如果正则表达式不合法,会抛出异常,影响页面显示。这里便捕获异常,不影响页面显示
|
||||
try {
|
||||
// 先把前后的/和g去掉才能生成正则表达式
|
||||
const matchesIterator = props.response?.matchAll(
|
||||
new RegExp(expressionForm.value.expression.replace(/^\/|\/$|\/g$/g, ''), 'g')
|
||||
);
|
||||
if (matchesIterator) {
|
||||
const matches = Array.from(matchesIterator);
|
||||
try {
|
||||
if (expressionForm.value.expressionMatchingRule === 'EXPRESSION') {
|
||||
// 匹配表达式,取第一个匹配结果,是完整匹配结果
|
||||
matchResult.value = matches.map((e) => e[0]) || [];
|
||||
} else {
|
||||
matchResult.value = matches.map((e) => e.slice(1)).flat(Infinity) || []; // 匹配分组,取匹配结果的第二项开始,是分组匹配结果
|
||||
}
|
||||
} catch (error) {
|
||||
// 读取匹配数据错误说明无对应的匹配结果
|
||||
matchResult.value = [];
|
||||
isMatched.value = true;
|
||||
}
|
||||
} catch (error) {
|
||||
// 读取匹配数据错误说明无对应的匹配结果
|
||||
} else {
|
||||
matchResult.value = [];
|
||||
isMatched.value = true;
|
||||
}
|
||||
} else {
|
||||
} catch (error) {
|
||||
console.log(`正则匹配异常:${error}`);
|
||||
matchResult.value = [];
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue