<?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>20130</bug_id>
          
          <creation_ts>2012-11-28 19:22:12 +0000</creation_ts>
          <short_desc>[Templates]: &lt;template&gt; within &lt;template&gt; effectively resets the implied context</short_desc>
          <delta_ts>2013-01-04 03:26: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>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>79032</commentid>
    <comment_count>0</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-11-28 19:22:12 +0000</bug_when>
    <thetext>e.g. 

#data
&lt;body&gt;&lt;template&gt;&lt;tr&gt;&lt;/tr&gt;&lt;template&gt;&lt;/template&gt;&lt;td&gt;&lt;/td&gt;&lt;/template&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;template&gt;
|       #document-fragment
|         &lt;tr&gt;
|         &lt;template&gt;
|           #document-fragment
|         &lt;td&gt;

I actually don&apos;t have an opinion as to whether this is a bug, I just wanted to call it out (and I&apos;m including the above in the initial webkit patch).

In order to enforce a *single* implied context, a stack of template-&gt;contextTagNames would need to be kept along side the stack of open elements.

I kind of feel like its added complexity and there&apos;s no obvious harm to the above behavior.

Opinions?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79454</commentid>
    <comment_count>1</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-12-05 04:45:56 +0000</bug_when>
    <thetext>After thinking more about this, I think it&apos;s worth adding a bit more logic to the parser to ensure that, for any given parse, each template element has at most one implied context. Here&apos;s the case which convinced me:

Consider the following, which seems totally reasonable:

#data
&lt;body&gt;&lt;template&gt;&lt;thead&gt;&lt;/thead&gt;&lt;tr&gt;&lt;/tr&gt;&lt;tfoot&gt;&lt;/tfoot&gt;&lt;/template&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;template&gt;
|       #document-fragment
|         &lt;thead&gt;
|         &lt;tbody&gt;
|           &lt;tr&gt;
|         &lt;tfoot&gt;

Now insert a template after the &lt;thead&gt;

#data
&lt;body&gt;&lt;template&gt;&lt;thead&gt;&lt;/thead&gt;&lt;template&gt;&lt;/template&gt;&lt;tr&gt;&lt;/tr&gt;&lt;tfoot&gt;&lt;/tfoot&gt;&lt;/template&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;template&gt;
|       #document-fragment
|         &lt;thead&gt;
|         &lt;template&gt;
|           #document-fragment
|         &lt;tr&gt;

(i.e. because the implied element became &lt;tbody&gt; after the inner template was popped, the &lt;tfoot&gt; got thrown away.

-----

I propose that the parser maintain a map of open template elements to implied context tag. In Template Contents Mode, when the insertion mode gets set to something else, the corresponding tagName is set as the implied context tag for the template element. In resetInsertionModeAppropriately, if the current node is a template tag and it has a mapped context tag already, use that to set the insertion mode, otherwise set it to In Template Contents mode.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80376</commentid>
    <comment_count>2</comment_count>
    <who name="Adam Klein">adamk</who>
    <bug_when>2012-12-18 21:38:26 +0000</bug_when>
    <thetext>This has been fixed as per Rafael&apos;s suggestion in WebKit in http://trac.webkit.org/changeset/138059</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80885</commentid>
    <comment_count>3</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2013-01-04 03:26:47 +0000</bug_when>
    <thetext>http://dvcs.w3.org/hg/webcomponents/rev/281c9049bf2f</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>