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.
*