diff --git a/spec/cdata_spec.js b/spec/cdata_spec.js index 821179a5..c93b9fce 100644 --- a/spec/cdata_spec.js +++ b/spec/cdata_spec.js @@ -368,19 +368,30 @@ patronymic`; expect(result).toEqual(expected); }); - it("should not process entities in CDATA", function () { - const xmlData = ``; + it("should preserve carriage return characters in CDATA and text nodes", function () { + const xmlData = ` + + + line1\rline2 + `; - const expected = { xml: '<text>' }; + const expected = { + "properties": { + "property": [ + "This is a carriage return \r...", + "\r" + ], + "text": "line1\rline2" + } + }; const options = { - ignoreAttributes: false, + parseTagValue: false, + trimValues: false }; - const parser = new XMLParser(options); let result = parser.parse(xmlData); - - // console.log(JSON.stringify(result,null,4)); + // console.log(JSON.stringify(result, null, 4)); expect(result).toEqual(expected); }); }); diff --git a/src/xmlparser/OrderedObjParser.js b/src/xmlparser/OrderedObjParser.js index ec8d24d4..83f2ae3b 100644 --- a/src/xmlparser/OrderedObjParser.js +++ b/src/xmlparser/OrderedObjParser.js @@ -275,7 +275,7 @@ function buildAttributesMap(attrStr, jPath, tagName, force = false) { } } const parseXml = function (xmlData) { - xmlData = xmlData.replace(/\r\n?/g, "\n"); //TODO: remove this line + // xmlData = xmlData.replace(/\r\n?/g, "\n"); // Removed: incorrectly replaces \r in CDATA and text nodes const xmlObj = new xmlNode('!xml'); let currentNode = xmlObj; let textData = "";