fix(接口测试): “推荐jsonpath断言”功能中,点击数组或对象生成的结果中数字变成了字符串

--bug=1027330 --user=白奇 【接口测试】github#25109,“推荐jsonpath断言”功能中,点击数组或对象生成的结果中数字变成了字符串 https://www.tapd.cn/55049933/s/1397922
This commit is contained in:
baiqi 2023-07-26 16:35:43 +08:00 committed by fit2-zhao
parent b7d59b1665
commit 7f4c7a1a6b
5 changed files with 39 additions and 8 deletions

View File

@ -9,6 +9,7 @@
"report": "NODE_ENV=analyze vue-cli-service build" "report": "NODE_ENV=analyze vue-cli-service build"
}, },
"dependencies": { "dependencies": {
"@ba1q1/vue-easy-tree": "^1.1.0",
"@ckeditor/ckeditor5-build-classic": "^18.0.0", "@ckeditor/ckeditor5-build-classic": "^18.0.0",
"@ckeditor/ckeditor5-vue": "^1.0.1", "@ckeditor/ckeditor5-vue": "^1.0.1",
"@form-create/element-ui": "^2.5.8", "@form-create/element-ui": "^2.5.8",
@ -17,8 +18,8 @@
"@fortawesome/free-regular-svg-icons": "^5.12.0", "@fortawesome/free-regular-svg-icons": "^5.12.0",
"@fortawesome/free-solid-svg-icons": "^5.12.0", "@fortawesome/free-solid-svg-icons": "^5.12.0",
"@fortawesome/vue-fontawesome": "^0.1.9", "@fortawesome/vue-fontawesome": "^0.1.9",
"@ba1q1/vue-easy-tree": "^1.1.0",
"axios": "^0.27.2", "axios": "^0.27.2",
"decimal.js": "^10.4.3",
"diffable-html": "^4.0.0", "diffable-html": "^4.0.0",
"echarts": "^5.0.2", "echarts": "^5.0.2",
"el-table-infinite-scroll": "^1.0.10", "el-table-infinite-scroll": "^1.0.10",
@ -44,6 +45,7 @@
"lodash.isnumber": "^3.0.3", "lodash.isnumber": "^3.0.3",
"lodash.isobject": "^3.0.2", "lodash.isobject": "^3.0.2",
"lodash.isstring": "^4.0.1", "lodash.isstring": "^4.0.1",
"lossless-json": "^2.0.11",
"mavon-editor": "2.10.4", "mavon-editor": "2.10.4",
"md5": "^2.3.0", "md5": "^2.3.0",
"metersphere-frontend": "file:../../framework/sdk-parent/frontend", "metersphere-frontend": "file:../../framework/sdk-parent/frontend",

View File

@ -10,6 +10,9 @@
<template v-slot:header> <template v-slot:header>
<ms-instructions-icon :content="tip" /> <ms-instructions-icon :content="tip" />
{{ tip }} {{ tip }}
<div class="jsonpath-tip">
{{ $t('api_test.request.extract.json_path_tip') }}
</div>
</template> </template>
<jsonpath-picker :code="data" v-on:path="pathChangeHandler" ref="jsonpathPicker" /> <jsonpath-picker :code="data" v-on:path="pathChangeHandler" ref="jsonpathPicker" />
</ms-drawer> </ms-drawer>
@ -20,6 +23,7 @@ import Vue from 'vue';
import JsonPathPicker from 'vue-jsonpath-picker'; import JsonPathPicker from 'vue-jsonpath-picker';
import MsDrawer from 'metersphere-frontend/src/components/MsDrawer'; import MsDrawer from 'metersphere-frontend/src/components/MsDrawer';
import MsInstructionsIcon from 'metersphere-frontend/src/components/MsInstructionsIcon'; import MsInstructionsIcon from 'metersphere-frontend/src/components/MsInstructionsIcon';
import { parse, isSafeNumber } from 'lossless-json';
let dotReplace = '#DOT_MASK#'; let dotReplace = '#DOT_MASK#';
@ -73,17 +77,27 @@ export default {
close() { close() {
this.visible = false; this.visible = false;
}, },
parseAndValidateNumber(value) {
if (!isSafeNumber(value) || Number(value).toString().length < value.length) {
// 0 JS
return `Number(${value.toString()})`;
}
return Number(value);
},
removeNumberFunctionFromString(string) {
const regex = /"?Number\(([\d.e+-]+)\)"?/g;
return string.replace(regex, '$1');
},
open(objStr) { open(objStr) {
this.data = {}; this.data = {};
try { try {
let stringedJSON = objStr.replace(/(?<=[:\[,])\s*(-?\d+(\.\d+)?)(?=\s*([,\]}]))/g, '"$1"');
let param; let param;
let JSONBig = require('json-bigint')({ storeAsString: true }); let JSONBig = require('json-bigint')({ storeAsString: true });
// //
try { try {
param = JSON.parse(JSON.stringify(JSONBig.parse(stringedJSON))); param = parse(objStr, undefined, this.parseAndValidateNumber);
} catch (e) { } catch (e) {
param = JSON.parse(JSON.stringify(JSONBig.parse(objStr))); param = JSONBig.parse(objStr);
} }
if (param instanceof Array) { if (param instanceof Array) {
this.$warning('不支持解析JSON数组'); this.$warning('不支持解析JSON数组');
@ -158,6 +172,7 @@ export default {
} else { } else {
childObj = childObj + ''; childObj = childObj + '';
} }
childObj = this.removeNumberFunctionFromString(childObj);
return { return {
key: param, key: param,
value: childObj, value: childObj,
@ -180,6 +195,12 @@ export default {
margin-left: 6px; margin-left: 6px;
} }
.jsonpath-tip {
font-size: 12px;
padding: 5px;
color: grey;
}
:deep(.el-icon-close:hover) { :deep(.el-icon-close:hover) {
font-size: 18px; font-size: 18px;
font-weight: bold; font-weight: bold;

View File

@ -679,7 +679,7 @@ const message = {
"Note: The system will automatically synchronize at 00:00:00 every day", "Note: The system will automatically synchronize at 00:00:00 every day",
case_priority_option_check_error: case_priority_option_check_error:
"Use case levels need to add option values in order, for example: P", "Use case levels need to add option values in order, for example: P",
remote_search_tip: "Enter a user name to search users for you" remote_search_tip: "Enter a user name to search users for you",
}, },
workspace: { workspace: {
id: "Workspace ID", id: "Workspace ID",
@ -1065,7 +1065,8 @@ const message = {
input_phone: "Please enter phone number", input_phone: "Please enter phone number",
special_characters_are_not_supported: special_characters_are_not_supported:
"Special characters are not supported", "Special characters are not supported",
chinese_characters_are_not_supported: "Chinese characters are not supported", chinese_characters_are_not_supported:
"Chinese characters are not supported",
mobile_number_format_is_incorrect: "Phone number format is incorrect", mobile_number_format_is_incorrect: "Phone number format is incorrect",
email_format_is_incorrect: "Email format is incorrect", email_format_is_incorrect: "Email format is incorrect",
delete_confirm: "Are you sure you want to delete this User?", delete_confirm: "Are you sure you want to delete this User?",
@ -1928,7 +1929,8 @@ const message = {
'Special characters "$ () * +. [] \\ ^ {} |" need to be escaped as "\\ "+"special characters", such as "\\$"', 'Special characters "$ () * +. [] \\ ^ {} |" need to be escaped as "\\ "+"special characters", such as "\\$"',
xpath_info: xpath_info:
"Select the extraction method according to the content format of the request response", "Select the extraction method according to the content format of the request response",
assert_info: "According to the content format of the request response, select the assertion method", assert_info:
"According to the content format of the request response, select the assertion method",
regular_match: "Regular match", regular_match: "Regular match",
none: "Do not verify []", none: "Do not verify []",
value_eq: "Value-equal to [value=]", value_eq: "Value-equal to [value=]",
@ -1961,6 +1963,8 @@ const message = {
suggest_tip: "Click the note to add the JSONPath extraction", suggest_tip: "Click the note to add the JSONPath extraction",
json_path_suggest: "JSONPath Extraction Suggest", json_path_suggest: "JSONPath Extraction Suggest",
json_path_clear: "Clear JSONPath Extraction", json_path_clear: "Clear JSONPath Extraction",
json_path_tip:
"Note: When the number is too long, the decimal places are all 0, or other situations where precision will be lost in JavaScript, Number() will be added to solve the problem of digital precision, and JSONPath will convert it to a number after extraction",
}, },
processor: { processor: {
pre_exec_script: "PreProcessor", pre_exec_script: "PreProcessor",
@ -3670,7 +3674,7 @@ const message = {
}, },
jar_config: { jar_config: {
upload_limit_size: "Upload file size cannot exceed 50MB!", upload_limit_size: "Upload file size cannot exceed 50MB!",
} },
}; };
export default { export default {

View File

@ -1894,6 +1894,8 @@ const message = {
suggest_tip: "点击便签添加JSONPath提取", suggest_tip: "点击便签添加JSONPath提取",
json_path_suggest: "推荐JSONPath提取", json_path_suggest: "推荐JSONPath提取",
json_path_clear: "清空JSONPath提取", json_path_clear: "清空JSONPath提取",
json_path_tip:
"注:当数字超长、小数位全为 0或其他在 JavaScript 内会丢失精度的情况下,会加上 Number()以解决数字精度问题JSONPath 提取后会转换为数字",
}, },
processor: { processor: {
pre_exec_script: "预执行脚本", pre_exec_script: "预执行脚本",

View File

@ -1893,6 +1893,8 @@ const message = {
suggest_tip: "點擊便簽添加JSONPath提取", suggest_tip: "點擊便簽添加JSONPath提取",
json_path_suggest: "推薦JSONPath提取", json_path_suggest: "推薦JSONPath提取",
json_path_clear: "清空JSONPath提取", json_path_clear: "清空JSONPath提取",
json_path_tip:
"注:當數字超長、小數位全為 0或其他在 JavaScript 內會丟失精度的情況下,會加上 Number()以解決數字精度問題JSONPath 提取後會轉換為數字",
}, },
processor: { processor: {
pre_exec_script: "預執行腳本", pre_exec_script: "預執行腳本",