<?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>18613</bug_id>
          
          <creation_ts>2012-08-17 22:55:41 +0000</creation_ts>
          <short_desc>[Templates]: Section 7 Parsing HTML Templates needs to be re-written</short_desc>
          <delta_ts>2012-09-07 04:41:07 +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="Tony Ross [MSFT]">tross</assigned_to>
          <cc>dglazkov</cc>
    
    <cc>rafaelw</cc>
    
    <cc>tross</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>72389</commentid>
    <comment_count>0</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-08-17 22:55:41 +0000</bug_when>
    <thetext>To be reflect the prior consensus (on public-webapps) about implied context parsing.

The basic idea is this:

While parsing children of the template element, act as if IN_HEAD, but append any produced nodes to the template element&apos;s content. When the first &quot;determining&quot; start tag is encountered, set the context element based on the indentity of that tag, reset the insertion mode appropriately and continue.

Non-determining start tags must include: template, style, script, link.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72395</commentid>
    <comment_count>1</comment_count>
    <who name="Tony Ross [MSFT]">tross</who>
    <bug_when>2012-08-17 23:54:40 +0000</bug_when>
    <thetext>We&apos;ll also need an explicit clause for non-whitespace text (else we&apos;ll end up implying a closing HEAD tag). Basically this clause will add non-whitespace text to the DOM without exiting implied context parsing (so we&apos;ll keep searching for a &quot;determining&quot; start tag afterward).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72709</commentid>
    <comment_count>2</comment_count>
    <who name="Tony Ross [MSFT]">tross</who>
    <bug_when>2012-08-24 18:12:46 +0000</bug_when>
    <thetext>http://dvcs.w3.org/hg/webcomponents/rev/557c7e693458</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72951</commentid>
    <comment_count>3</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-08-28 23:45:46 +0000</bug_when>
    <thetext>I implemented the current spec text (including &quot;clear the stack back to XXX&quot;, and I have some questions:

Here are html5lib test cases that illustrate the issues:

// Does naked template go into &lt;head&gt; or &lt;body&gt; -- as is, it goes into &lt;head&gt;
#data
&lt;template&gt;Hello&lt;/template&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;template&gt;
|       &quot;Hello&quot;

// Can template exist as a child of &lt;html&gt; -- as is, it gets put into &lt;head&gt;
#data
&lt;html&gt;&lt;template&gt;&lt;div&gt;
#errors
#document
| &lt;html&gt;
|   &lt;template&gt;
|     &lt;div&gt;

// Can template exist as a child of &lt;colgroup&gt; -- as is, no
#data
&lt;table&gt;&lt;colgroup&gt;&lt;template&gt;Hello
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;table&gt;
|       &lt;colgroup&gt;
|         &lt;template&gt;
|           &quot;Hello&quot;

// Can template exist as a child of &lt;frameset&gt; -- as is, no
#data
&lt;frameset&gt;&lt;template&gt;&lt;frame&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;frameset&gt;
|       &lt;template&gt;
|         &lt;frame&gt;

// Reset insertion mode picks InBody for &lt;/head&gt;, which is wrong for this case. -- as is, this actually hits a series of assertions, and I&apos;m pretty sure it&apos;s wrong.
#data
&lt;head&gt;&lt;template&gt;&lt;div&gt;&lt;/div&gt;&lt;/template&gt;&lt;/head&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|     &lt;template&gt;
|       &lt;div&gt;

// Should &quot;in cell&quot; be modified to &quot;close the cell&quot; on &lt;/template&gt; (e.g. with &lt;/table&gt;, &lt;/tbody&gt;, &lt;/tfoot&gt;, &lt;/thead&gt;, &lt;/tr&gt;) -- as is, &lt;/tr&gt; wil lbe ignored and &lt;div&gt; appended to &lt;td&gt;
#data
&lt;body&gt;&lt;template&gt;&lt;td&gt;&lt;/tr&gt;&lt;div&gt;&lt;/template&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;template&gt;
|       &lt;td&gt;
|       &lt;div&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73024</commentid>
    <comment_count>4</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-08-29 22:29:25 +0000</bug_when>
    <thetext>Also, just to make sure this is what we want:

#data
&lt;body&gt;&lt;template&gt;&lt;tr&gt;&lt;div&gt;&lt;/div&gt;&lt;/tr&gt;&lt;/template&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;template&gt;
|       &lt;tr&gt;
|       &lt;div&gt;

Note that the div is foster parented *after* the &lt;tr&gt;, not before.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73025</commentid>
    <comment_count>5</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-08-29 22:31:48 +0000</bug_when>
    <thetext>Likewise this one:

#data
&lt;body&gt;&lt;template&gt;&lt;div&gt;&lt;tr&gt;&lt;/tr&gt;&lt;/div&gt;&lt;/template&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;template&gt;
|       &lt;div&gt;

(throws away the &lt;tr&gt; -- which I think makes sense).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73076</commentid>
    <comment_count>6</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-08-30 17:59:29 +0000</bug_when>
    <thetext>Decisions:

On Thu, Aug 30, 2012 at 10:52 AM, Rafael Weinstein &lt;rafaelw@google.com&gt; wrote:
&gt; // Does naked template go into &lt;head&gt; or &lt;body&gt; -- as is, it goes into &lt;head&gt;
&gt; #data
&gt; &lt;template&gt;Hello&lt;/template&gt;
&gt; #errors
&gt; #document
&gt; | &lt;html&gt;
&gt; |   &lt;head&gt;
&gt; |   &lt;body&gt;
&gt; |     &lt;template&gt;
&gt; |       &quot;Hello&quot;

This is correct (analog is &lt;script&gt;)

&gt;
&gt; // Can template exist as a child of &lt;html&gt; -- as is, it gets put into &lt;head&gt;
&gt; #data
&gt; &lt;html&gt;&lt;template&gt;&lt;div&gt;
&gt; #errors
&gt; #document
&gt; | &lt;html&gt;
&gt; |   &lt;template&gt;
&gt; |     &lt;div&gt;
&gt;

This is correct (analog is &lt;script&gt;)

&gt; // Can template exist as a child of &lt;colgroup&gt; -- as is, no
&gt; #data
&gt; &lt;table&gt;&lt;colgroup&gt;&lt;template&gt;Hello
&gt; #errors
&gt; #document
&gt; | &lt;html&gt;
&gt; |   &lt;head&gt;
&gt; |   &lt;body&gt;
&gt; |     &lt;table&gt;
&gt; |       &lt;colgroup&gt;
&gt; |         &lt;template&gt;
&gt; |           &quot;Hello&quot;

We need parser edits for this. Relevant test which should pass is

// Can template exist as a child of &lt;colgroup&gt; -- as is, no
#data
&lt;table&gt;&lt;colgroup&gt;&lt;template&gt;&lt;col&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;table&gt;
|       &lt;colgroup&gt;
|         &lt;template&gt;
|           &lt;col&gt;

&gt;
&gt; // Can template exist as a child of &lt;frameset&gt; -- as is, no
&gt; #data
&gt; &lt;frameset&gt;&lt;template&gt;&lt;frame&gt;
&gt; #errors
&gt; #document
&gt; | &lt;html&gt;
&gt; |   &lt;head&gt;
&gt; |   &lt;body&gt;
&gt; |     &lt;frameset&gt;
&gt; |       &lt;template&gt;
&gt; |         &lt;frame&gt;

We need parser edits for this. Relevant test which should pass is

#data
&lt;frameset&gt;&lt;template&gt;&lt;frame&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;frameset&gt;
|     &lt;template&gt;
|       &lt;frame&gt;

&gt;
&gt; // Reset insertion mode picks InBody for &lt;/head&gt;, which is wrong for this case.
&gt; -- as is, this actually hits a series of assertions, and I&apos;m pretty sure it&apos;s
&gt; wrong.
&gt; #data
&gt; &lt;head&gt;&lt;template&gt;&lt;div&gt;&lt;/div&gt;&lt;/template&gt;&lt;/head&gt;
&gt; #errors
&gt; #document
&gt; | &lt;html&gt;
&gt; |   &lt;head&gt;
&gt; |     &lt;template&gt;
&gt; |       &lt;div&gt;

Step 11 of reset insertion mode appropriately should be:

If node is a head element and node is the context element, then switch the insertion mode to &quot;in body&quot; (&quot;in body&quot;! not &quot;in head&quot;!) and abort these steps. (fragment case)
otherwise, switch the insertion mode to &quot;in head&quot; and abort these steps.

&gt;
&gt; // Should &quot;in cell&quot; be modified to &quot;close the cell&quot; on &lt;/template&gt; (e.g. with
&gt; &lt;/table&gt;, &lt;/tbody&gt;, &lt;/tfoot&gt;, &lt;/thead&gt;, &lt;/tr&gt;) -- as is, &lt;/tr&gt; wil lbe ignored
&gt; and &lt;div&gt; appended to &lt;td&gt;
&gt; #data
&gt; &lt;body&gt;&lt;template&gt;&lt;td&gt;&lt;/tr&gt;&lt;div&gt;&lt;/template&gt;
&gt; #errors
&gt; #document
&gt; | &lt;html&gt;
&gt; |   &lt;head&gt;
&gt; |   &lt;body&gt;
&gt; |     &lt;template&gt;
&gt; |       &lt;td&gt;
&gt; |       &lt;div&gt;

This is correct, but we need spec text that http://dev.w3.org/html5/spec/parsing.html#has-an-element-in-table-scope includes &lt;template&gt;

&gt;
&gt; Also, just to make sure this is what we want:
&gt;
&gt; #data
&gt; &lt;body&gt;&lt;template&gt;&lt;tr&gt;&lt;div&gt;&lt;/div&gt;&lt;/tr&gt;&lt;/template&gt;
&gt; #errors
&gt; #document
&gt; | &lt;html&gt;
&gt; |   &lt;head&gt;
&gt; |   &lt;body&gt;
&gt; |     &lt;template&gt;
&gt; |       &lt;tr&gt;
&gt; |       &lt;div&gt;
&gt;
&gt; Note that the div is foster parented *after* the &lt;tr&gt;, not before.

Correct behavior.

&gt;
&gt; Likewise this one:
&gt;
&gt; #data
&gt; &lt;body&gt;&lt;template&gt;&lt;div&gt;&lt;tr&gt;&lt;/tr&gt;&lt;/div&gt;&lt;/template&gt;
&gt; #errors
&gt; #document
&gt; | &lt;html&gt;
&gt; |   &lt;head&gt;
&gt; |   &lt;body&gt;
&gt; |     &lt;template&gt;
&gt; |       &lt;div&gt;
&gt;
&gt; (throws away the &lt;tr&gt; -- which I think makes sense).

Correct behavior.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73200</commentid>
    <comment_count>7</comment_count>
    <who name="Tony Ross [MSFT]">tross</who>
    <bug_when>2012-09-04 21:42:01 +0000</bug_when>
    <thetext>http://dvcs.w3.org/hg/webcomponents/rev/6b0813f30f10</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73372</commentid>
    <comment_count>8</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-09-06 21:42:42 +0000</bug_when>
    <thetext>For the colgroup case to work (e.g.:

#data
&lt;table&gt;&lt;colgroup&gt;&lt;template&gt;&lt;col&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;table&gt;
|       &lt;colgroup&gt;
|         &lt;template&gt;
|           &lt;col&gt;

), template contents mode needs to set the insertion mode to in column group when a col tag is encountered.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73374</commentid>
    <comment_count>9</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-09-06 22:26:23 +0000</bug_when>
    <thetext>For the frameset case to work, template contents mode needs to set the insertion mode to in frameset
when a frame tag is encountered.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73375</commentid>
    <comment_count>10</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-09-06 22:50:52 +0000</bug_when>
    <thetext>The in head edit to reset insertion mode should read:

Modify the step which begins &quot;If node is a head element...&quot; to be:

If node is a head element and node is the context element, then switch the insertion mode to &quot;in body&quot; (&quot;in body&quot;! not &quot;in head&quot;) and abort these steps (fragment case). Otherwise, switch the insertion mode to &quot;in head&quot;, and abort these steps.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73376</commentid>
    <comment_count>11</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-09-06 23:08:25 +0000</bug_when>
    <thetext>To clarify

&gt; // Should &quot;in cell&quot; be modified to &quot;close the cell&quot; on &lt;/template&gt; (e.g. with
&gt; &lt;/table&gt;, &lt;/tbody&gt;, &lt;/tfoot&gt;, &lt;/thead&gt;, &lt;/tr&gt;) -- as is, &lt;/tr&gt; wil lbe ignored
&gt; and &lt;div&gt; appended to &lt;td&gt;
&gt; #data
&gt; &lt;body&gt;&lt;template&gt;&lt;td&gt;&lt;/tr&gt;&lt;div&gt;&lt;/template&gt;
&gt; #errors
&gt; #document
&gt; | &lt;html&gt;
&gt; |   &lt;head&gt;
&gt; |   &lt;body&gt;
&gt; |     &lt;template&gt;
&gt; |       &lt;td&gt;
&gt; |       &lt;div&gt;

This is correct, but we need spec text that
http://dev.w3.org/html5/spec/parsing.html#has-an-element-in-table-scope
includes &lt;template&gt;

Should actually be:

#data
&lt;body&gt;&lt;template&gt;&lt;td&gt;&lt;/tr&gt;&lt;div&gt;&lt;/template&gt;
#errors
#document
| &lt;html&gt;
|   &lt;head&gt;
|   &lt;body&gt;
|     &lt;template&gt;
|       &lt;td&gt;
|         &lt;div&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73385</commentid>
    <comment_count>12</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-09-07 00:29:36 +0000</bug_when>
    <thetext>also, it&apos;s probably worth clarifying for in cell mode:

An end tag whose tag name is one of: &quot;table&quot;, &quot;tbody&quot;, &quot;tfoot&quot;, &quot;thead&quot;, &quot;tr&quot;
If the stack of open elements does not have an element in table scope with the same tag name as that of the token (which can only happen for &quot;tbody&quot;, &quot;tfoot&quot; and &quot;thead&quot;, or in the fragment case), then this is a parse error and the token must be ignored.

Otherwise, close the cell (see below) and reprocess the current token.

---

That this can now happen if a template contents is currently being parsed (webkit was hitting an assertion which I had to relax by checking if templateTag is in tableScope.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73386</commentid>
    <comment_count>13</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-09-07 00:43:42 +0000</bug_when>
    <thetext>note that i have patch for these edits which I&apos;ll submit as soon as I gain write access.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73391</commentid>
    <comment_count>14</comment_count>
    <who name="Rafael Weinstein">rafaelw</who>
    <bug_when>2012-09-07 04:41:07 +0000</bug_when>
    <thetext>http://dvcs.w3.org/hg/webcomponents/rev/923f79e27d75</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>