Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions spec/cdata_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,19 +368,30 @@ patronymic</person></root>`;
expect(result).toEqual(expected);
});

it("should not process entities in CDATA", function () {
const xmlData = `<xml><![CDATA[&lt;text&gt;]]></xml>`;
it("should preserve carriage return characters in CDATA and text nodes", function () {
const xmlData = `<properties>
<property><![CDATA[This is a carriage return \r...]]></property>
<property><![CDATA[\r]]></property>
<text>line1\rline2</text>
</properties>`;

const expected = { xml: '&lt;text&gt;' };
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);
});
});
2 changes: 1 addition & 1 deletion src/xmlparser/OrderedObjParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down