From b01bff565fcde89a67ba7c0215810b95802c55e3 Mon Sep 17 00:00:00 2001 From: jiangkai43 Date: Sat, 8 Jul 2023 20:06:21 +0800 Subject: [PATCH] Deal with special characters in CDATA https://gitee.com/openharmony/commonlibrary_ets_utils/issues/I7JNVN Signed-off-by: jiangkai43 --- .../src/main/js/test/convertxml.test.js | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/commonlibrary/ets_utils/convertxml_lib_standard/src/main/js/test/convertxml.test.js b/commonlibrary/ets_utils/convertxml_lib_standard/src/main/js/test/convertxml.test.js index e66c95cf6..f92a5a3cd 100644 --- a/commonlibrary/ets_utils/convertxml_lib_standard/src/main/js/test/convertxml.test.js +++ b/commonlibrary/ets_utils/convertxml_lib_standard/src/main/js/test/convertxml.test.js @@ -977,20 +977,17 @@ describe('XmlTest', function () { * @tc.desc: To convert XML text to JavaScript object. */ it('testConvert028', 0, function () { - let xml = ' \t ]]>'; + let xml = '\r\n \t ]]>'; let conv = new convertxml.ConvertXML(); let options = {trim : false, declarationKey:"_declaration", instructionKey : "_instruction", attributesKey : "_attributes", textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype", commentKey : "_comment", parentKey : "_parent", typeKey : "_type", nameKey : "_name", elementsKey : "_elements"} - let result = JSON.stringify(conv.convert(xml, options)); - let str1 = '{"_elements":[{"_type":"cdata","_cdata":"'+ - ' \\t'+ - ' '+ - '\\t '+ - '"}]}' - expect(result).assertEqual(str1); + let result = conv.convertToJSObject(xml, options); + let cdata = result._elements[0]._cdata; + let str1 = ' \\t \\r\\n \\t '; + expect(cdata).assertEqual(str1); }) /** @@ -998,26 +995,17 @@ describe('XmlTest', function () { * @tc.desc: To convert XML text to JavaScript object. */ it('testConvert029', 0, function () { - let xml = ' " and & \t ]]>'; + let xml = ' " and & \t ]]>'; let conv = new convertxml.ConvertXML(); let options = {trim : false, declarationKey:"_declaration", instructionKey : "_instruction", attributesKey : "_attributes", textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype", commentKey : "_comment", parentKey : "_parent", typeKey : "_type", nameKey : "_name", elementsKey : "_elements"} - let result = JSON.stringify(conv.convert(xml, options)); - console.log("LHC..." + result); - let str1 = '{"_elements":[{"_type":"cdata","_cdata":"'+ - ' \\t'+ - ' data"},{"_type":"cdata","_cdata":"< '+ - '> '+ - '\\"'+ - ' and'+ - ' & '+ - '\\t '+ - '"}]}'; - console.log("LHC..." + str1); - expect(result).assertEqual(str1); + let result = conv.convertToJSObject(xml, options); + let cdata = result._elements[0]._cdata; + let str = ' \\t data\\n< > \" and & \\t '; + expect(cdata).assertEqual(str); }) /** -- GitLab