This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24833 - AAA step 1 should only pop when current node is not in the list of active formatting elements
Summary: AAA step 1 should only pop when current node is not in the list of active for...
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 22926
  Show dependency treegraph
 
Reported: 2014-02-27 01:20 UTC by William Chen
Modified: 2014-03-06 19:48 UTC (History)
8 users (show)

See Also:


Attachments

Description William Chen 2014-02-27 01:20:00 UTC
The fix in Bug 22926 was intended to make properly nested tags behave better but it has a strange side effect on improperly nested tags.

Consider the following example from the html5lib-tests that produces a very different tree before and after the change:

<b id=a> // active formatting elements = [<b id=a>]
<p>
<b id=b> // active formatting elements = [<b id=a>, <b id=b>]
</p> // *1
</b> // *2
Text // *3

*1: Pops stack back to <b id=a>, list of formatting elements is unchanged.
*2: Name matches current element, pops <b id=a> off stack, and removes <b id=a> from list of active formatting elements. In the old world, the AAA would remove <b id=b> from the list of active formatting elements and leave the stack untouched.
*3: "reconstruct the active formatting elements" will recreate <b id=b> because it is not on the stack. In the old world, nothing would be reconstructed because <b id=a> is the only item in the list of active formatting elements and it is on the stack.

I propose that step 1 of the AAA should be reworded to something similar to the following (which preserves the old-world behavior of the above example):

If the current node is an HTML element whose tag name is subject, and current node is not in the list of active formatting elements, then run these substeps:
Pop current node off the stack of open elements.
Abort the adoption agency algorithm.

I feel that this handles the Noah's Arc quirkiness (cause of bug 22926) more precisely, since we only check against the stack with priority in the case where the Noah's Arc clause removed the node's entry in the active formatting elements list, otherwise we just let the AAA handle it.
Comment 1 Ian 'Hixie' Hickson 2014-03-05 00:16:45 UTC
Looking at the case from bug 22926:

As currently specced:

   <code a>     <!-- A, list is A -->
     <code>     <!-- B, list is A,B -->
      <code>    <!-- C, list is A,B,C -->
       <code>   <!-- D, list is A,B,C,D -->
        <div>
         <code> <!-- E; B gets removed from the list so list is A,C,D,E -->
        </div>  <!-- pop stack to A,B,C,D; list is still A,C,D,E -->
   </code>      <!-- closes D; stack is A,B,C; list is A,C,E -->
   </code>      <!-- closes C; stack is A,B; list is A,E -->
   </code>      <!-- closes B; stack is A; list is E -->
   </code>      <!-- closes A; list is E -->
   TEXT         <!-- reopens E, inserts text -->

As proposed by comment 0:

   <code a>     <!-- A, list is A -->
     <code>     <!-- B, list is A,B -->
      <code>    <!-- C, list is A,B,C -->
       <code>   <!-- D, list is A,B,C,D -->
        <div>
         <code> <!-- E; B gets removed from the list so list is A,C,D,E -->
        </div>  <!-- pop stack to A,B,C,D; list is still A,C,D,E -->
   </code>      <!-- closes E via AAA.6; stack is A,B,C,D; list is A,C,D -->
   </code>      <!-- closes D via AAA.10; stack is A,B,C; list is A,C -->
   </code>      <!-- closes C via AAA.10; stack is A,B; list is A -->
   </code>      <!-- closes B via new first step; stack is A; list is A -->
   TEXT         <!-- inserts text -->

So the proposal makes sense to me.
Comment 2 Ian 'Hixie' Hickson 2014-03-05 23:21:37 UTC
Ok, I'm planning on changing the parser as suggested in comment 0. Let me know if you disagree.
Comment 3 contributor 2014-03-06 19:48:48 UTC
Checked in as WHATWG revision r8531.
Check-in comment: PARSER CHANGE: Change the Adoption Agency Algorithm so that it only pops the current element if it's not on the list of formatting elements, since otherwise we can end up with close tags closing things out of order even when they're all there.
http://html5.org/tools/web-apps-tracker?from=8530&to=8531