From 3a92c5924230e98a6c43a22408b19efe6050ddc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E9=B9=B0?= <17kungfuboy@gmail.com> Date: Thu, 25 Aug 2022 16:25:43 +0800 Subject: [PATCH] fix: xml2json bug --- .../src/app/utils/data-transfer/data-transfer.utils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/workbench/browser/src/app/utils/data-transfer/data-transfer.utils.ts b/src/workbench/browser/src/app/utils/data-transfer/data-transfer.utils.ts index a4cc8f53..13c61c38 100644 --- a/src/workbench/browser/src/app/utils/data-transfer/data-transfer.utils.ts +++ b/src/workbench/browser/src/app/utils/data-transfer/data-transfer.utils.ts @@ -96,7 +96,7 @@ export const xml2json = (tmpl) => { let index = null; while (xml) { // * handle end tags - if (xml.trim().substring(0, 2) === ' { parent.children.push(last); stack.push(parent); } - xml = xml.trim().substring(str.length); + xml = xml.trim().substring(str.length).trim(); continue; } // * handle start tags @@ -185,7 +185,7 @@ export const xml2UiData = (text) => { * @returns */ export const json2XML: (o: object, tab?) => string = (o, tab) => { - const toXml = function(v, name, ind) { + const toXml = function (v, name, ind) { let xml = ''; if (v instanceof Array) { for (let i = 0, n = v.length; i < n; i++) { @@ -241,7 +241,7 @@ export const text2UiData: (text: string) => uiData = (text) => { data: text, }; const textType = whatTextType(text); - result.textType = ['xml', 'json'].includes(textType) ? textType as ApiBodyType : ApiBodyType.Raw; + result.textType = ['xml', 'json'].includes(textType) ? (textType as ApiBodyType) : ApiBodyType.Raw; switch (result.textType) { case 'xml': { result.data = xml2UiData(text); @@ -268,7 +268,7 @@ export const text2UiData: (text: string) => uiData = (text) => { * @param inputOptions * @returns */ -export const uiData2Json = function(eoapiArr: ApiEditBody[], inputOptions) { +export const uiData2Json = function (eoapiArr: ApiEditBody[], inputOptions) { inputOptions = inputOptions || {}; let result = {}; const loopFun = (inputArr, inputObject) => {