Skip to content
Closed
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
14 changes: 14 additions & 0 deletions spec/entities_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<!doctype html><html><body>hi</body></html>`;
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 = `<?xml version='1.0' standalone='no'?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
Expand Down
8 changes: 1 addition & 7 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
7 changes: 1 addition & 6 deletions src/xmlparser/DocTypeReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/xmlparser/OrderedObjParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down