From 790d1b15a93918e2497a0a957a86645a76872059 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Mon, 7 Sep 2026 18:27:36 +0100 Subject: [PATCH] Mozilla bug 2049083 - Ensure nobr follows "any other end tag" --- .../htmlparser/impl/TreeBuilder.java | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/nu/validator/htmlparser/impl/TreeBuilder.java b/src/nu/validator/htmlparser/impl/TreeBuilder.java index 631184e3..464a9d40 100644 --- a/src/nu/validator/htmlparser/impl/TreeBuilder.java +++ b/src/nu/validator/htmlparser/impl/TreeBuilder.java @@ -2081,7 +2081,9 @@ public final void startTag(ElementName elementName, reconstructTheActiveFormattingElements(); if (TreeBuilder.NOT_FOUND_ON_STACK != findLastInScope("nobr")) { errFooSeenWhenFooOpen(name); - adoptionAgencyEndTag("nobr"); + if (!adoptionAgencyEndTag("nobr")) { + anyOtherEndTagInBody("nobr"); + } reconstructTheActiveFormattingElements(); } appendToCurrentNodeAndPushFormattingElementMayFoster( @@ -3695,30 +3697,8 @@ public final void endTag(ElementName elementName) throws SAXException { // else handle like any other tag // CPPONLY: MOZ_FALLTHROUGH; default: - if (isCurrent(name)) { - pop(); - break endtagloop; - } - - eltPos = currentPtr; - for (;;) { - StackNode node = stack[eltPos]; - if (node.ns == "http://www.w3.org/1999/xhtml" && node.name == name) { - generateImpliedEndTags(); - if (errorHandler != null - && !isCurrent(name)) { - errUnclosedElements(eltPos, name); - } - while (currentPtr >= eltPos) { - pop(); - } - break endtagloop; - } else if (eltPos == 0 || node.isSpecial()) { - errStrayEndTag(name); - break endtagloop; - } - eltPos--; - } + anyOtherEndTagInBody(name); + break endtagloop; } // CPPONLY: MOZ_FALLTHROUGH; case IN_HEAD: @@ -4433,6 +4413,36 @@ private void removeFromListOfActiveFormattingElements(int pos) { listPtr--; } + /** + * The "any other end tag" entry of the "in body" insertion mode. + */ + private void anyOtherEndTagInBody(@Local String name) throws SAXException { + if (isCurrent(name)) { + pop(); + return; + } + + int eltPos = currentPtr; + for (;;) { + StackNode node = stack[eltPos]; + if (node.ns == "http://www.w3.org/1999/xhtml" && node.name == name) { + generateImpliedEndTags(); + if (errorHandler != null + && !isCurrent(name)) { + errUnclosedElements(eltPos, name); + } + while (currentPtr >= eltPos) { + pop(); + } + return; + } else if (eltPos == 0 || node.isSpecial()) { + errStrayEndTag(name); + return; + } + eltPos--; + } + } + /** * Adoption agency algorithm. *