From 8565b0d692bb3a19bf97a5f8a6c633bffcbc2db4 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Sun, 6 Sep 2020 16:59:03 +0800 Subject: [PATCH] close #42 fallback to html when doctype is invalid --- src/rebuild.ts | 2 +- test/__snapshots__/integration.ts.snap | 9 +++++++++ test/html/invalid-doctype.html | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/html/invalid-doctype.html diff --git a/src/rebuild.ts b/src/rebuild.ts index 23025797..f2a8291d 100644 --- a/src/rebuild.ts +++ b/src/rebuild.ts @@ -85,7 +85,7 @@ function buildNode( return doc.implementation.createDocument(null, '', null); case NodeType.DocumentType: return doc.implementation.createDocumentType( - n.name, + n.name || 'html', n.publicId, n.systemId, ); diff --git a/test/__snapshots__/integration.ts.snap b/test/__snapshots__/integration.ts.snap index 7bf95acf..855d73eb 100644 --- a/test/__snapshots__/integration.ts.snap +++ b/test/__snapshots__/integration.ts.snap @@ -175,6 +175,15 @@ exports[`[html file]: invalid-attribute.html 1`] = ` " `; +exports[`[html file]: invalid-doctype.html 1`] = ` +" + + + Invalid Doctype + + " +`; + exports[`[html file]: invalid-tagname.html 1`] = ` " diff --git a/test/html/invalid-doctype.html b/test/html/invalid-doctype.html new file mode 100644 index 00000000..395c916d --- /dev/null +++ b/test/html/invalid-doctype.html @@ -0,0 +1,9 @@ + + + + + + Invalid Doctype + + +