From d3634ba9941881e6308f2be3a659857c84a4f3b2 Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Fri, 14 Aug 2020 18:35:55 +0900 Subject: [PATCH] =?UTF-8?q?Ensure=20namespace-aware=20=E2=80=9Cclear=20the?= =?UTF-8?q?=20stack=E2=80=9D=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change ensures that for all cases with spec requirements in the form “clear the stack back to a foo context” — which involves checking for elements with particular names — we only look for elements in the HTML namespace, rather than additionally looking for elements which aren’t in the HTML namespace but that also have those particular names. Otherwise, without this change, we aren’t in conformance with the spec requirements, and we fail several cases in the html5lib-tests suite. Fixes https://github.com/validator/htmlparser/issues/33 --- src/nu/validator/htmlparser/impl/TreeBuilder.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nu/validator/htmlparser/impl/TreeBuilder.java b/src/nu/validator/htmlparser/impl/TreeBuilder.java index 7b78b1b7..63ee22f7 100644 --- a/src/nu/validator/htmlparser/impl/TreeBuilder.java +++ b/src/nu/validator/htmlparser/impl/TreeBuilder.java @@ -3898,8 +3898,9 @@ private void endTagTemplateInHead() throws SAXException { private int findLastInTableScopeOrRootTemplateTbodyTheadTfoot() { for (int i = currentPtr; i > 0; i--) { - if (stack[i].getGroup() == TreeBuilder.TBODY_OR_THEAD_OR_TFOOT || - stack[i].getGroup() == TreeBuilder.TEMPLATE) { + if (stack[i].ns == "http://www.w3.org/1999/xhtml" + && (stack[i].getGroup() == TreeBuilder.TBODY_OR_THEAD_OR_TFOOT + || stack[i].getGroup() == TreeBuilder.TEMPLATE)) { return i; } } @@ -4667,7 +4668,7 @@ private int findLastOrRoot(@Local String name) { private int findLastOrRoot(int group) { for (int i = currentPtr; i > 0; i--) { - if (stack[i].getGroup() == group) { + if (stack[i].ns == "http://www.w3.org/1999/xhtml" && stack[i].getGroup() == group) { return i; } }