diff --git a/spec/entities_spec.js b/spec/entities_spec.js index ff231a86..5663f0f5 100644 --- a/spec/entities_spec.js +++ b/spec/entities_spec.js @@ -3,6 +3,23 @@ import { EntityDecoder, COMMON_HTML } from "@nodable/entities"; describe("XMLParser Entities", function () { + it("should decode XML numeric references without enabling HTML entities", function () { + const xml = 'AB😊©&#65;'; + for (const htmlEntities of [false, true]) { + const parser = new XMLParser({ ignoreAttributes: false, htmlEntities }); + const result = parser.parse(xml); + expect(result.r["@_a"]).toBe("AB😊"); + expect(result.r["#text"]).toBe(htmlEntities ? "AB😊©A" : "AB😊©A"); + } + }); + + it("should leave numeric references untouched when entity processing is disabled", function () { + const parser = new XMLParser({ ignoreAttributes: false, processEntities: false }); + expect(parser.parse('B')).toEqual({ + r: { "#text": "B", "@_a": "A" } + }); + }); + it("should parse attributes with valid names, default entities", function () { const xmlData = ` 1 @@ -30,7 +47,7 @@ describe("XMLParser Entities", function () { "a:c": "test&\nтест<\ntest", "a:el": "<<b>2]]]]>&a", "c:string": { - "#text": "страхования » от суммы его активов", + "#text": "страхования » от суммы его активов", "@_lang": "ru" } } @@ -722,9 +739,6 @@ describe("@nodable/entities", function () { it("should remove '#x1B' ncr as per XML version 1.0 with default config", function () { const xmlData = ``; - const expected = { - "root": '' - } const options = { //ignoreAttributes: false, //should work without this processEntities: true, @@ -736,12 +750,9 @@ describe("@nodable/entities", function () { expect(result.root.length).toEqual(0); }) - it("should leave '#x1B' ncr as per XML version 1.1 with default config", function () { + it("should decode '#x1B' ncr as per XML version 1.1 with default config", function () { const xmlData = ``; - const expected = { - "root": '' - } const options = { //ignoreAttributes: false, //should work without this processEntities: true @@ -750,6 +761,6 @@ describe("@nodable/entities", function () { let result = parser.parse(xmlData); // console.log(JSON.stringify(result, null, 4)); - expect(result.root.length).toEqual(11); + expect(result.root).toEqual("\x1b\x1b"); }) }) \ No newline at end of file diff --git a/src/xmlparser/OrderedObjParser.js b/src/xmlparser/OrderedObjParser.js index 58c6a5f2..a2847514 100644 --- a/src/xmlparser/OrderedObjParser.js +++ b/src/xmlparser/OrderedObjParser.js @@ -96,7 +96,7 @@ export default class OrderedObjParser { else if (this.options.htmlEntities === true) namedEntities = { ...COMMON_HTML, ...CURRENCY }; this.entityDecoder = new EntityDecoder({ namedEntities: { ...namedEntities, ...externalEntities }, - numericAllowed: this.options.htmlEntities, + numericAllowed: true, limit: { maxTotalExpansions: this.options.processEntities.maxTotalExpansions, maxExpandedLength: this.options.processEntities.maxExpandedLength,