From 70abd998f7b99092c503b4e57b09715140229885 Mon Sep 17 00:00:00 2001 From: iska Date: Wed, 18 May 2016 19:51:42 +0200 Subject: [PATCH] Fix adoption agency algorithm according to the latest specification This implements the specification change: https://github.com/whatwg/html/commit/22ce3c31 Current implementation should pass all new html5lib test cases, including those from Blink, WebKit, and namespace sensitivity. See related: https://github.com/html5lib/html5lib-tests/issues/78 https://bugzilla.mozilla.org/show_bug.cgi?id=901319 https://lists.w3.org/Archives/Public/public-html/2013Aug/0002.html https://lists.w3.org/Archives/Public/public-whatwg-archive/2013Jul/0401.html https://lists.w3.org/Archives/Public/public-whatwg-archive/2013Jul/0006.html --- HTMLKit/HTMLParser.m | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/HTMLKit/HTMLParser.m b/HTMLKit/HTMLParser.m index a94a4ef..230ad53 100644 --- a/HTMLKit/HTMLParser.m +++ b/HTMLKit/HTMLParser.m @@ -588,20 +588,29 @@ HTMLElement *lastNode = furthestBlock; NSUInteger index = [_stackOfOpenElements indexOfElement:node]; - for (int innerLoopCounter = 0; innerLoopCounter < 3; innerLoopCounter ++) { - index--; + int innerLoopCounter = 0; + while (YES) { + + innerLoopCounter += 1; + index -= 1; + node = _stackOfOpenElements[index]; + if ([node isEqual:formattingElement]) { + break; + } + + if (innerLoopCounter > 3 && [_listOfActiveFormattingElements containsElement:node]) { + [_listOfActiveFormattingElements removeElement:node]; + continue; + } + if (![_listOfActiveFormattingElements containsElement:node]) { [_stackOfOpenElements removeElement:node]; continue; } - if ([node isEqual:formattingElement]) { - break; - } - HTMLElement *newElement = [node copy]; [_listOfActiveFormattingElements replaceElementAtIndex:[_listOfActiveFormattingElements indexOfElement:node] withElement:newElement];