xmldom
xmldom copied to clipboard
Fix <!DOCTYPE> parsing
Consider the following test cases:
var docA=new DOMParser().parseFromString('<!DOCTYPE foo> <foo/>',"text/xml"),
docB=new DOMParser().parseFromString('<!DOCTYPE foo SYSTEM "bar"> <foo/>',"text/xml"),
docC=new DOMParser().parseFromString('<!DOCTYPE foo SYSTEM "bar" [<!ENTITY bar "BAR">]> <foo/>',"text/xml"),
docD=new DOMParser().parseFromString('<!DOCTYPE foo [<!ENTITY bar "BAR">]> <foo>&bar;</foo>',"text/xml");
console.log(docA.doctype);
console.log(docB.doctype);
console.log(docC.doctype);
console.log(docD.doctype);
Current output:
null
null
null
entity not found:&bar;
null
Expected output: (e.g, produced in in Chrome)
<!DOCTYPE foo>
<!DOCTYPE foo SYSTEM "bar">
<!DOCTYPE foo SYSTEM "bar">
<!DOCTYPE foo>
The first one is easy-fixer: doctype field just left blank. One can check that DocumentType node is already there:
docA:
Document {
doctype: null,
implementation: { _features: {} },
childNodes:
{ '0':
DocumentType {
name: 'foo',
nodeName: 'foo',
publicId: false,
systemId: false,
.....
Next, checking the DocumentType itself, some issues with systemId are apparent. In the both, external and internal DTD cases:
docB:
DocumentType {
name: 'foo',
nodeName: 'foo',
publicId: false,
systemId: '>',
docC:
DocumentType {
name: 'foo',
nodeName: 'foo',
publicId: false,
systemId: '[',
lineNumber: 1,
And, finally, some support for dealing with entities would be great. The "options.entityMap" patch might solve the problem provided with some mechanisms for handling parsed DTD definitions.
Thanks.
A "options.entityMap" patch would be great! #131