diff --git a/spec/entities_spec.js b/spec/entities_spec.js index ff231a86..14d94f7e 100644 --- a/spec/entities_spec.js +++ b/spec/entities_spec.js @@ -73,6 +73,20 @@ describe("XMLParser Entities", function () { expect(result).toEqual(expected); }); + it("should parse a lowercase (HTML-style) doctype the same as an uppercase one", function () { + const xmlData = `hi`; + const expected = { + "html": { + "body": "hi" + } + }; + + const parser = new XMLParser({ ignoreDeclaration: true }); + let result = parser.parse(xmlData, true); + + expect(result).toEqual(expected); + }); + it("should parse XML with DOCTYPE without internal DTD", function () { const xmlData = ` diff --git a/src/validator.js b/src/validator.js index 6f9904f0..01728b9b 100644 --- a/src/validator.js +++ b/src/validator.js @@ -229,13 +229,7 @@ function readCommentAndCDATA(xmlData, i) { } } else if ( xmlData.length > i + 8 && - xmlData[i + 1] === 'D' && - xmlData[i + 2] === 'O' && - xmlData[i + 3] === 'C' && - xmlData[i + 4] === 'T' && - xmlData[i + 5] === 'Y' && - xmlData[i + 6] === 'P' && - xmlData[i + 7] === 'E' + xmlData.substring(i + 1, i + 8).toUpperCase() === 'DOCTYPE' ) { let angleBracketsCount = 1; for (i += 8; i < xmlData.length; i++) { diff --git a/src/xmlparser/DocTypeReader.js b/src/xmlparser/DocTypeReader.js index d65f8c17..2c99f646 100644 --- a/src/xmlparser/DocTypeReader.js +++ b/src/xmlparser/DocTypeReader.js @@ -14,12 +14,7 @@ export default class DocTypeReader { const entities = Object.create(null); let entityCount = 0; - if (xmlData[i + 3] === 'O' && - xmlData[i + 4] === 'C' && - xmlData[i + 5] === 'T' && - xmlData[i + 6] === 'Y' && - xmlData[i + 7] === 'P' && - xmlData[i + 8] === 'E') { + if (xmlData.substring(i + 3, i + 9).toUpperCase() === 'OCTYPE') { i = i + 9; let angleBracketsCount = 1; let hasBody = false, comment = false; diff --git a/src/xmlparser/OrderedObjParser.js b/src/xmlparser/OrderedObjParser.js index 58c6a5f2..5c5fff30 100644 --- a/src/xmlparser/OrderedObjParser.js +++ b/src/xmlparser/OrderedObjParser.js @@ -389,7 +389,7 @@ const parseXml = function (xmlData) { } i = endIndex; } else if (c1 === 33 - && xmlData.charCodeAt(i + 2) === 68) { //'!D' + && (xmlData.charCodeAt(i + 2) === 68 || xmlData.charCodeAt(i + 2) === 100)) { //'!D' or '!d' if (this.doctypefound) throw new Error("Multiple DOCTYPE declarations found."); this.doctypefound = true; const result = docTypeReader.readDocType(xmlData, i);