You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Obviously there's no practical use in replacing an element with itself, but robustness is in the edge cases.
Take the document:
body
| h1
| div
If we were to replace the h1 with itself via h1.replaceWith(h1), it's next sibling, in this case the div, would be deleted and the h1 would remain - but without a reference to it's parent.
In this state, the node traverser fails when rendering the tostring().
Minimal reproducable :
val doc =Document("")
val targetElement =Element("h1")
doc.body().appendChild(targetElement)
// During the replace, the target is removed from the children.// 'Ensure child list' within the replace operation is// different if there is no children, so we must add another child.//// Also, there must be children *after* the target element, else// there will be an index out of bounds during the replace operation.
doc.body().appendChild(Element("div"))
targetElement.replaceWith(targetElement)
// The document can no longer be rendered to string.
assertDoesNotThrow {
println(doc)
}
This can be solved with a simple equality check.
Self assigned, pr soon
The text was updated successfully, but these errors were encountered:
Obviously there's no practical use in replacing an element with itself, but robustness is in the edge cases.
Take the document:
If we were to replace the h1 with itself via
h1.replaceWith(h1)
, it's next sibling, in this case the div, would be deleted and the h1 would remain - but without a reference to it's parent.In this state, the node traverser fails when rendering the tostring().
Minimal reproducable :
This can be solved with a simple equality check.
Self assigned, pr soon
The text was updated successfully, but these errors were encountered: