Skip to content

Commit

Permalink
Handle setting innerHTML to the empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
Zirro authored and domenic committed Apr 24, 2017
1 parent 58a7028 commit 461c638
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/jsdom/living/nodes/Element-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ function setInnerHTML(document, node, html) {
clearChildNodes(node);
}

if (html !== "") {
if (node.nodeName === "#document") {
document._htmlToDom.appendHtmlToDocument(html, node);
} else {
document._htmlToDom.appendHtmlToElement(html, node);
}
if (node.nodeName === "#document") {
document._htmlToDom.appendHtmlToDocument(html, node);
} else {
document._htmlToDom.appendHtmlToElement(html, node);
}
}

Expand Down
1 change: 1 addition & 0 deletions test/web-platform-tests/to-upstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe("Local tests in Web Platform Test format (to-upstream)", () => {
"dom/nodes/ParentNode-querySelector-escapes.html",
"dom/nodes/Text-wholeText.html",
"domparsing/DOMParser-dont-upstream.html",
"domparsing/innerhtml-08.html",
"domparsing/insert-adjacent.html",
"domparsing/outerhtml-03.html",
"FileAPI/blob/Blob-isClosed.html",
Expand Down
20 changes: 20 additions & 0 deletions test/web-platform-tests/to-upstream/domparsing/innerhtml-08.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>innerHTML to empty string</title>
<link rel="help" href="https://w3c.github.io/DOM-Parsing/#dom-element-innerhtml">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
"use strict";

test(() => {
const doc = document.createElement("html");
doc.innerHTML = "<head><title>foo</title></head><body></body>";

doc.innerHTML = "";

assert_true(doc.getElementsByTagName("body")[0] instanceof HTMLBodyElement);

}, "Setting innerHTML to empty string");
</script>

0 comments on commit 461c638

Please sign in to comment.