Skip to content

Commit 70abd99

Browse files
committed
Fix adoption agency algorithm according to the latest specification
This implements the specification change: whatwg/html@22ce3c31 Current implementation should pass all new html5lib test cases, including those from Blink, WebKit, and namespace sensitivity. See related: html5lib/html5lib-tests#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
1 parent bb948e0 commit 70abd99

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

HTMLKit/HTMLParser.m

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,18 +588,27 @@ - (BOOL)runAdoptionAgencyAlgorithmForTagName:(NSString *)tagName
588588
HTMLElement *lastNode = furthestBlock;
589589

590590
NSUInteger index = [_stackOfOpenElements indexOfElement:node];
591-
for (int innerLoopCounter = 0; innerLoopCounter < 3; innerLoopCounter ++) {
592591

593-
index--;
592+
int innerLoopCounter = 0;
593+
while (YES) {
594+
595+
innerLoopCounter += 1;
596+
index -= 1;
597+
594598
node = _stackOfOpenElements[index];
595599

596-
if (![_listOfActiveFormattingElements containsElement:node]) {
597-
[_stackOfOpenElements removeElement:node];
600+
if ([node isEqual:formattingElement]) {
601+
break;
602+
}
603+
604+
if (innerLoopCounter > 3 && [_listOfActiveFormattingElements containsElement:node]) {
605+
[_listOfActiveFormattingElements removeElement:node];
598606
continue;
599607
}
600608

601-
if ([node isEqual:formattingElement]) {
602-
break;
609+
if (![_listOfActiveFormattingElements containsElement:node]) {
610+
[_stackOfOpenElements removeElement:node];
611+
continue;
603612
}
604613

605614
HTMLElement *newElement = [node copy];

0 commit comments

Comments
 (0)