diff --git a/src/main/java/org/htmlunit/html/DomNode.java b/src/main/java/org/htmlunit/html/DomNode.java index 039acb81b9..5928b80d9e 100644 --- a/src/main/java/org/htmlunit/html/DomNode.java +++ b/src/main/java/org/htmlunit/html/DomNode.java @@ -1008,6 +1008,13 @@ public void insertBefore(final DomNode newNode) { return; } + if (newNode instanceof DomDocumentFragment) { + for (final DomNode child : newNode.getChildren()) { + insertBefore(child); + } + return; + } + // clean up the new node, in case it is being moved if (newNode.getParentNode() != null) { newNode.detach(); diff --git a/src/test/java/org/htmlunit/html/DomNode2Test.java b/src/test/java/org/htmlunit/html/DomNode2Test.java index db05da3225..108ee7efd6 100644 --- a/src/test/java/org/htmlunit/html/DomNode2Test.java +++ b/src/test/java/org/htmlunit/html/DomNode2Test.java @@ -167,4 +167,72 @@ public void textContentCdata() throws Exception { loadPageVerifyTitle2(content); } + @Test + @Alerts({"before:new,old", "after:old,new", + "prepend:new,old", "append:old,new", "appendChild:old,new", + "insertBefore:new,old", + "replaceWith:new", "replaceChild:new", "replaceChildren:new"}) + public void documentFragment_dissolution() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + "\n" + + "
old
\n" + + "
old
\n" + + "
old
\n" + + "
old
\n" + + "
old
\n" + + "
old
\n" + + "
old
\n" + + "
old
\n" + + "
old
\n" + + ""; + + loadPageVerifyTitle2(html); + } + }