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 20130 - [Templates]: <template> within <template> effectively resets the implied context
Summary: [Templates]: <template> within <template> effectively resets the implied context
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 15476
  Show dependency treegraph
 
Reported: 2012-11-28 19:22 UTC by Rafael Weinstein
Modified: 2013-01-04 03:26 UTC (History)
1 user (show)

See Also:


Attachments

Description Rafael Weinstein 2012-11-28 19:22:12 UTC
e.g. 

#data
<body><template><tr></tr><template></template><td></td></template>
#errors
#document
| <html>
|   <head>
|   <body>
|     <template>
|       #document-fragment
|         <tr>
|         <template>
|           #document-fragment
|         <td>

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

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

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

Opinions?
Comment 1 Rafael Weinstein 2012-12-05 04:45:56 UTC
After thinking more about this, I think it'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's the case which convinced me:

Consider the following, which seems totally reasonable:

#data
<body><template><thead></thead><tr></tr><tfoot></tfoot></template>
#errors
#document
| <html>
|   <head>
|   <body>
|     <template>
|       #document-fragment
|         <thead>
|         <tbody>
|           <tr>
|         <tfoot>

Now insert a template after the <thead>

#data
<body><template><thead></thead><template></template><tr></tr><tfoot></tfoot></template>
#errors
#document
| <html>
|   <head>
|   <body>
|     <template>
|       #document-fragment
|         <thead>
|         <template>
|           #document-fragment
|         <tr>

(i.e. because the implied element became <tbody> after the inner template was popped, the <tfoot> 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.
Comment 2 Adam Klein 2012-12-18 21:38:26 UTC
This has been fixed as per Rafael's suggestion in WebKit in http://trac.webkit.org/changeset/138059
Comment 3 Rafael Weinstein 2013-01-04 03:26:47 UTC
http://dvcs.w3.org/hg/webcomponents/rev/281c9049bf2f