From 0c610eb6b8e47252d9e0e2088d8a67ce31ccd1e5 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Fri, 25 Sep 2026 08:47:56 +0000 Subject: [PATCH] Mozilla bug 2071398 - Redirect replaced elements into the adoption agency's next kept clone Differential Revision: https://phabricator.services.mozilla.com/D328164 --- .../htmlparser/impl/TreeBuilder.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/nu/validator/htmlparser/impl/TreeBuilder.java b/src/nu/validator/htmlparser/impl/TreeBuilder.java index 26b8af30..dc20165f 100644 --- a/src/nu/validator/htmlparser/impl/TreeBuilder.java +++ b/src/nu/validator/htmlparser/impl/TreeBuilder.java @@ -4537,6 +4537,7 @@ private boolean adoptionAgencyEndTag(@Local String name) throws SAXException { int bookmark = formattingEltListPos; int nodePos = furthestBlockPos; StackNode lastNode = furthestBlock; // weak ref + // CPPONLY: sanitizerDeferRedirect(furthestBlock.node); int j = 0; for (;;) { ++j; @@ -4599,9 +4600,11 @@ private boolean adoptionAgencyEndTag(@Local String name) throws SAXException { // } XXX AAA CHANGE // When the sanitizer replaces the clone with its children, // the spec does not move lastNode into it, so that lastNode - // keeps both its position and its identity, and redirects the - // content of the clone to the common ancestor instead. - // CPPONLY: if (!sanitizerRedirectsClone(node.node, insertionCommonAncestor)) { + // keeps both its position and its identity. The clone's + // content is redirected to wherever the next kept clone, or + // failing that the common ancestor, gets lastNode. + // CPPONLY: if (!sanitizerRedirectsClone(node.node)) { + // CPPONLY: sanitizerRedirectPending(node.node); detachFromParent(lastNode.node); appendElement(lastNode.node, nodeFromStackWithBlinkCompat(nodePos)); lastNode = node; @@ -4612,14 +4615,12 @@ private boolean adoptionAgencyEndTag(@Local String name) throws SAXException { if (commonAncestor.isFosterParenting()) { fatal(); detachFromParent(lastNode.node); - insertIntoFosterParent(lastNode.node - // CPPONLY: , furthestBlock.node - ); + insertIntoFosterParent(lastNode.node); } else { - // The content of a furthest block that the sanitizer replaced - // with its children follows the content it already has, so it - // goes wherever lastNode goes. - // CPPONLY: sanitizerRedirectFurthestBlock(furthestBlock.node, insertionCommonAncestor); + // The content of elements the sanitizer replaced with their + // children follows the content they already have, so it goes + // wherever lastNode goes. + // CPPONLY: sanitizerRedirectPending(insertionCommonAncestor); detachFromParent(lastNode.node); appendElement(lastNode.node, insertionCommonAncestor); } @@ -4648,6 +4649,11 @@ private boolean adoptionAgencyEndTag(@Local String name) throws SAXException { // furthestBlockPos is now off by one and points to the slot after // it insertIntoStack(formattingClone, furthestBlockPos); + // Elements the sanitizer replaced with their children that sit + // below the furthest block in the stack now have the clone + // between them and the block, so their content goes into the + // clone from here on. + // CPPONLY: sanitizerRedirectBelowFormattingClone(furthestBlockPos); } return true; } @@ -4967,20 +4973,18 @@ private StackNode createStackNode(ElementName elementName, T node, @Local Str return instance; } - private void insertIntoFosterParent(T child - // CPPONLY: , T furthestBlock - ) throws SAXException { + private void insertIntoFosterParent(T child) throws SAXException { int tablePos = findLastOrRoot(TreeBuilder.TABLE); int templatePos = findLastOrRoot(TreeBuilder.TEMPLATE); if (templatePos >= tablePos) { - // CPPONLY: sanitizerRedirectFurthestBlock(furthestBlock, stack[templatePos].node); + // CPPONLY: sanitizerRedirectPending(stack[templatePos].node); appendElement(child, stack[templatePos].node); return; } StackNode node = stack[tablePos]; - // CPPONLY: sanitizerRedirectFurthestBlockToFosterParent(furthestBlock, node.node, stack[tablePos - 1].node); + // CPPONLY: sanitizerRedirectPendingToFosterParent(node.node, stack[tablePos - 1].node); insertFosterParentedChild(child, node.node, stack[tablePos - 1].node); }