fix(接口测试): “推荐jsonpath断言”功能中,点击数组或对象生成的结果中数字变成了字符串
--bug=1027330 --user=白奇 【接口测试】github#25109,“推荐jsonpath断言”功能中,点击数组或对象生成的结果中数字变成了字符串 https://www.tapd.cn/55049933/s/1397922
This commit is contained in:
parent
b7d59b1665
commit
7f4c7a1a6b
|
@ -9,6 +9,7 @@
|
|||
"report": "NODE_ENV=analyze vue-cli-service build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ba1q1/vue-easy-tree": "^1.1.0",
|
||||
"@ckeditor/ckeditor5-build-classic": "^18.0.0",
|
||||
"@ckeditor/ckeditor5-vue": "^1.0.1",
|
||||
"@form-create/element-ui": "^2.5.8",
|
||||
|
@ -17,8 +18,8 @@
|
|||
"@fortawesome/free-regular-svg-icons": "^5.12.0",
|
||||
"@fortawesome/free-solid-svg-icons": "^5.12.0",
|
||||
"@fortawesome/vue-fontawesome": "^0.1.9",
|
||||
"@ba1q1/vue-easy-tree": "^1.1.0",
|
||||
"axios": "^0.27.2",
|
||||
"decimal.js": "^10.4.3",
|
||||
"diffable-html": "^4.0.0",
|
||||
"echarts": "^5.0.2",
|
||||
"el-table-infinite-scroll": "^1.0.10",
|
||||
|
@ -44,6 +45,7 @@
|
|||
"lodash.isnumber": "^3.0.3",
|
||||
"lodash.isobject": "^3.0.2",
|
||||
"lodash.isstring": "^4.0.1",
|
||||
"lossless-json": "^2.0.11",
|
||||
"mavon-editor": "2.10.4",
|
||||
"md5": "^2.3.0",
|
||||
"metersphere-frontend": "file:../../framework/sdk-parent/frontend",
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
<template v-slot:header>
|
||||
<ms-instructions-icon :content="tip" />
|
||||
{{ tip }}
|
||||
<div class="jsonpath-tip">
|
||||
{{ $t('api_test.request.extract.json_path_tip') }}
|
||||
</div>
|
||||
</template>
|
||||
<jsonpath-picker :code="data" v-on:path="pathChangeHandler" ref="jsonpathPicker" />
|
||||
</ms-drawer>
|
||||
|
@ -20,6 +23,7 @@ import Vue from 'vue';
|
|||
import JsonPathPicker from 'vue-jsonpath-picker';
|
||||
import MsDrawer from 'metersphere-frontend/src/components/MsDrawer';
|
||||
import MsInstructionsIcon from 'metersphere-frontend/src/components/MsInstructionsIcon';
|
||||
import { parse, isSafeNumber } from 'lossless-json';
|
||||
|
||||
let dotReplace = '#DOT_MASK#';
|
||||
|
||||
|
@ -73,17 +77,27 @@ export default {
|
|||
close() {
|
||||
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) {
|
||||
this.data = {};
|
||||
try {
|
||||
let stringedJSON = objStr.replace(/(?<=[:\[,])\s*(-?\d+(\.\d+)?)(?=\s*([,\]}]))/g, '"$1"');
|
||||
let param;
|
||||
let JSONBig = require('json-bigint')({ storeAsString: true });
|
||||
// 解决精度丢失问题
|
||||
try {
|
||||
param = JSON.parse(JSON.stringify(JSONBig.parse(stringedJSON)));
|
||||
param = parse(objStr, undefined, this.parseAndValidateNumber);
|
||||
} catch (e) {
|
||||
param = JSON.parse(JSON.stringify(JSONBig.parse(objStr)));
|
||||
param = JSONBig.parse(objStr);
|
||||
}
|
||||
if (param instanceof Array) {
|
||||
this.$warning('不支持解析JSON数组');
|
||||
|
@ -158,6 +172,7 @@ export default {
|
|||
} else {
|
||||
childObj = childObj + '';
|
||||
}
|
||||
childObj = this.removeNumberFunctionFromString(childObj);
|
||||
return {
|
||||
key: param,
|
||||
value: childObj,
|
||||
|
@ -180,6 +195,12 @@ export default {
|
|||
margin-left: 6px;
|
||||
}
|
||||
|
||||
.jsonpath-tip {
|
||||
font-size: 12px;
|
||||
padding: 5px;
|
||||
color: grey;
|
||||
}
|
||||
|
||||
:deep(.el-icon-close:hover) {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
|
|
|
@ -679,7 +679,7 @@ const message = {
|
|||
"Note: The system will automatically synchronize at 00:00:00 every day",
|
||||
case_priority_option_check_error:
|
||||
"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: {
|
||||
id: "Workspace ID",
|
||||
|
@ -1065,7 +1065,8 @@ const message = {
|
|||
input_phone: "Please enter phone number",
|
||||
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",
|
||||
email_format_is_incorrect: "Email format is incorrect",
|
||||
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 "\\$"',
|
||||
xpath_info:
|
||||
"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",
|
||||
none: "Do not verify []",
|
||||
value_eq: "Value-equal to [value=]",
|
||||
|
@ -1961,6 +1963,8 @@ const message = {
|
|||
suggest_tip: "Click the note to add the JSONPath extraction",
|
||||
json_path_suggest: "JSONPath Extraction Suggest",
|
||||
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: {
|
||||
pre_exec_script: "PreProcessor",
|
||||
|
@ -3670,7 +3674,7 @@ const message = {
|
|||
},
|
||||
jar_config: {
|
||||
upload_limit_size: "Upload file size cannot exceed 50MB!",
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
|
|
@ -1894,6 +1894,8 @@ const message = {
|
|||
suggest_tip: "点击便签添加JSONPath提取",
|
||||
json_path_suggest: "推荐JSONPath提取",
|
||||
json_path_clear: "清空JSONPath提取",
|
||||
json_path_tip:
|
||||
"注:当数字超长、小数位全为 0或其他在 JavaScript 内会丢失精度的情况下,会加上 Number()以解决数字精度问题,JSONPath 提取后会转换为数字",
|
||||
},
|
||||
processor: {
|
||||
pre_exec_script: "预执行脚本",
|
||||
|
|
|
@ -1893,6 +1893,8 @@ const message = {
|
|||
suggest_tip: "點擊便簽添加JSONPath提取",
|
||||
json_path_suggest: "推薦JSONPath提取",
|
||||
json_path_clear: "清空JSONPath提取",
|
||||
json_path_tip:
|
||||
"注:當數字超長、小數位全為 0或其他在 JavaScript 內會丟失精度的情況下,會加上 Number()以解決數字精度問題,JSONPath 提取後會轉換為數字",
|
||||
},
|
||||
processor: {
|
||||
pre_exec_script: "預執行腳本",
|
||||
|
|
Loading…
Reference in New Issue