fix(接口测试): 修复请求体字符串空格丢失问题

This commit is contained in:
RubyLiu 2023-06-26 15:07:03 +08:00 committed by f2c-ci-robot[bot]
parent cc2dace12e
commit 95c1a1af3f
2 changed files with 10 additions and 2 deletions

View File

@ -14,6 +14,9 @@ export const jsonParse = (jsonStr) => {
return parseBoolean(); return parseBoolean();
} else if (char === 'n') { } else if (char === 'n') {
return parseNull(); return parseNull();
} else if (char === ' ' || char === '\n') {
index++;
return parseValue();
} else { } else {
return parseNumber(); return parseNumber();
} }
@ -29,6 +32,9 @@ export const jsonParse = (jsonStr) => {
if (jsonStr[index] === ',') { if (jsonStr[index] === ',') {
index++; index++;
} }
while (jsonStr[index] === ' ' || jsonStr[index] === '\n') {
index++;
}
} }
index++; index++;
return obj; return obj;
@ -47,6 +53,9 @@ export const jsonParse = (jsonStr) => {
} }
function parseString() { function parseString() {
let str = ''; let str = '';
while(jsonStr[index] === ' ' || jsonStr[index] === '\n'){
index++;
}
index++; index++;
while (jsonStr[index] !== '"') { while (jsonStr[index] !== '"') {
str += jsonStr[index]; str += jsonStr[index];

View File

@ -257,8 +257,7 @@ export default {
if (this.body.format === 'JSON-SCHEMA') { if (this.body.format === 'JSON-SCHEMA') {
if (this.body.raw) { if (this.body.raw) {
try { try {
const tmpStr = trimAll(this.body.raw) const tmpObj = jsonParse(this.body.raw)
const tmpObj = jsonParse(tmpStr)
this.body.jsonSchema = MsConvert.format(tmpObj); this.body.jsonSchema = MsConvert.format(tmpObj);
} catch (e) { } catch (e) {
this.body.format = 'JSON'; this.body.format = 'JSON';