<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>20924</bug_id>
          
          <creation_ts>2013-02-09 01:32:48 +0000</creation_ts>
          <short_desc>[Templates]: processing an EOF token deep within a template which was opened in &lt;head&gt; may fail to run after-head work</short_desc>
          <delta_ts>2013-03-13 23:30:47 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>HISTORICAL - Component Model</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>15476</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Rafael Weinstein">rafaelw</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          <cc>adamk</cc>
    
    <cc>annevk</cc>
    
    <cc>dglazkov</cc>
    
    <cc>hsivonen</cc>
    
    <cc>ian</cc>
    
    <cc>tross</cc>
    
    <cc>wchen</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>82816</commentid>
    <comment_count>0</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-02-09 01:32:48 +0000</bug_when>
    <thetext>e.g.

#data
&lt;template&gt;&lt;div&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|     &lt;template&gt;
|       #document-fragment
|         &lt;div&gt;
|   &lt;body&gt;

With the current spec-text, the body element will fail to be produced because the EOF was reached in &quot;in body&quot; insertion mode which just stops parsing.

We could obviously solve this by disallowing &lt;template&gt; inside of &lt;head&gt;, but I think the impacts the design consistency of &lt;template&gt; and possibly cuts off legitimate use cases.

It seems like the right way to approach this is that the stack needs to unwind back past the first open template element, reset the insertion mode, and then reprocess the EOF token (thus if it was inside a &lt;head&gt; context, the parser will act as if &lt;/head&gt; and &lt;body&gt; had been seen).

Right now, &quot;in cell&quot;, &quot;in caption&quot; defer to &quot;in body&quot; for EOF (as &quot;anything else&quot;), &quot;in table body&quot;, &quot;in row&quot;, and &quot;in select in table&quot; defer to &quot;in table&quot;.

So the logic to pop past the first open template can go into &quot;in body&quot; and &quot;in table&quot; when processing EOF.

That leaves &quot;in coloumn group&quot; and &quot;in frameset&quot;.

It seems to me that &quot;in column group&quot; is table element, so it makes sense to make it defer to &quot;in table&quot; for EOF (its behavior is the same).

&quot;in frameset&quot; has the same behavior as &quot;in table&quot;, so it could either be spec&apos;d independently, or defer to &quot;in table&quot;, which might be a tad confusing (spec wise) since framesets aren&apos;t related to tables. Webkit will implement like the former, but I&apos;m fine with the later.

Thoughts?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82817</commentid>
    <comment_count>1</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-02-09 01:35:37 +0000</bug_when>
    <thetext>Note that popping back to the first opened template is a matter of popping from the stack, removing a template insertion mode if the popped node was a template, stopping either when the node about to be popped is the root node, or when all template insertion modes have been popped.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82827</commentid>
    <comment_count>2</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-02-09 02:34:23 +0000</bug_when>
    <thetext>Here&apos;s the webkit implementation of this:

https://bugs.webkit.org/show_bug.cgi?id=109338

Note that this patch implements everything described in comments 0 &amp; 1, AND in addition:

For &quot;in coloumn group&quot;, the rule for EOF must be:

-If the current node is the root html element, then stop parsing. (fragment case)
-Act as if an end tag with the tag name &quot;colgroup&quot; had been seen
-*AND* defer to the rules for &quot;in table&quot; for encountering a EOF.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82932</commentid>
    <comment_count>3</comment_count>
    <who name="William Chen">wchen</who>
    <bug_when>2013-02-11 23:40:17 +0000</bug_when>
    <thetext>Another approach we can take is to generate an implicit &lt;/template&gt; on EOF in the &quot;template contents&quot; mode. And then defer &quot;in body&quot;, &quot;in table&quot;, &quot;in column group&quot; and &quot;in frameset&quot; modes to &quot;template contents&quot; if in the &quot;template contents case&quot;. The algorithm to handle &lt;/template&gt; will pop the stack to the last template and it will generate parse errors for some weird looking markup. This should have the same tree output as the Rafael&apos;s solution because each nested template will pop the stack to the previous template until there are none left (instead of popping them all in one go).

I think this solution is simpler because we don&apos;t create a new algorithm that does almost the same thing as &lt;/template&gt;. Also, the spec is simpler because we don&apos;t need as much language, it&apos;s almost all just deferring cases to &quot;template contents&quot;. I think it&apos;s also easier to understand that we are handling a quirk in templates when we defer to &quot;template case&quot; rather than to &quot;in table&quot; for column group and frameset.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82935</commentid>
    <comment_count>4</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-02-12 00:08:24 +0000</bug_when>
    <thetext>Will makes a strong case for the conceptual cleanliness of his approach, and I&apos;d be happy with it. My only question is about the behavioral difference. In his approach, we process the EOF for every parent of a &lt;template&gt;, as opposed to just the parent of the outer-most &lt;template&gt;.

Anyone else have input here?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83841</commentid>
    <comment_count>5</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-02-28 21:42:50 +0000</bug_when>
    <thetext>I talked live with Tony about this and he agrees that the difference between the two approaches wouldn&apos;t currently be observable, but that Will&apos;s approach to specification is preferable.

I&apos;m fine with this. I will update the spec to reflect Will&apos;s proposal.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84375</commentid>
    <comment_count>6</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-03-13 23:30:47 +0000</bug_when>
    <thetext>Ok. I&apos;ve made the changes that Will suggests here:

https://dvcs.w3.org/hg/webcomponents/rev/2323115e29dd

Note that the EOF handling for &quot;in column group&quot; now *always* defers to &quot;in table&quot;. I believe this is simpler, and was always the case (the fake &lt;/colgroup&gt; tag can&apos;t be ignored in this EOF case because the previous step established that the root node is not &lt;html&gt;).</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>