Skip to content
Permalink
Browse files

[giow] (2) Add in some hard-coded limits for dealing with unclosed fo…

…rmatting elements to limit the explosive growth of the list of formatting elements in commonly-seen cases.

Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=10802

git-svn-id: http://svn.whatwg.org/webapps@5638 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information...
Hixie committed Oct 15, 2010
1 parent aeee15b commit 42d40e643b5d0028cd4072f53afd42fb57f4e7e9
Showing with 218 additions and 44 deletions.
  1. +71 −15 complete.html
  2. +71 −15 index
  3. +76 −14 source
<li><a href=#misnested-tags:-b-i-/b-/i><span class=secno>12.2.8.1 </span>Misnested tags: &lt;b&gt;&lt;i&gt;&lt;/b&gt;&lt;/i&gt;</a></li>
<li><a href=#misnested-tags:-b-p-/b-/p><span class=secno>12.2.8.2 </span>Misnested tags: &lt;b&gt;&lt;p&gt;&lt;/b&gt;&lt;/p&gt;</a></li>
<li><a href=#unexpected-markup-in-tables><span class=secno>12.2.8.3 </span>Unexpected markup in tables</a></li>
<li><a href=#scripts-that-modify-the-page-as-it-is-being-parsed><span class=secno>12.2.8.4 </span>Scripts that modify the page as it is being parsed</a></ol></ol></li>
<li><a href=#scripts-that-modify-the-page-as-it-is-being-parsed><span class=secno>12.2.8.4 </span>Scripts that modify the page as it is being parsed</a></li>
<li><a href=#unclosed-formatting-elements><span class=secno>12.2.8.5 </span>Unclosed formatting elements</a></ol></ol></li>
<li><a href=#serializing-html-fragments><span class=secno>12.3 </span>Serializing HTML fragments</a></li>
<li><a href=#parsing-html-fragments><span class=secno>12.4 </span>Parsing HTML fragments</a></li>
<li><a href=#named-character-references><span class=secno>12.5 </span>Named character references</a></ol></li>
created, so that further elements can be created for that token if
necessary.</p>

<p>When the steps below require the UA to <dfn id=reconstruct-the-active-formatting-elements>reconstruct the
<p>When the steps below require the UA to <dfn id=push-onto-the-list-of-active-formatting-elements>push onto the list of
active formatting elements</dfn> an element <var title="">element</var>, the UA must perform the following steps:</p>

<ol><li><p>If there are already three elements in the <a href=#list-of-active-formatting-elements>list of
active formatting elements</a> after the last list marker, if
any, or anywhere in the list if there are no list markers, that
have the same tag name, namespace, and attributes as <var title="">element</var>, then remove the earliest such element from
the <a href=#list-of-active-formatting-elements>list of active formatting elements</a>. For these
purposes, the attributes must be compared as they were when the
elements were created by the parser; two elements have the same
attributes if all their parsed attributes can be paired such that
the two attributes in each pair have identical names, namespaces,
and values (the order of the attributes does not matter).</p>

<p class=note>This is the Noah's Ark clause. But with three per
family instead of two.</li> <!-- A sort of polyamorous Noah's
Ark, if you will. -->

<li><p>Add <var title="">element</var> to the <a href=#list-of-active-formatting-elements>list of active
formatting elements</a>.</li>

</ol><p>When the steps below require the UA to <dfn id=reconstruct-the-active-formatting-elements>reconstruct the
active formatting elements</dfn>, the UA must perform the following
steps:</p>

<p><a href=#reconstruct-the-active-formatting-elements>Reconstruct the active formatting elements</a>, if
any.</p>

<p><a href=#insert-an-html-element>Insert an HTML element</a> for the token. Add that
element to the <a href=#list-of-active-formatting-elements>list of active formatting
elements</a>.</p>
<p><a href=#insert-an-html-element>Insert an HTML element</a> for the token. <a href=#push-onto-the-list-of-active-formatting-elements>Push
onto the list of active formatting elements</a> that
element.</p>

</dd>

<p><a href=#reconstruct-the-active-formatting-elements>Reconstruct the active formatting elements</a>, if
any.</p>

<p><a href=#insert-an-html-element>Insert an HTML element</a> for the token. Add that
element to the <a href=#list-of-active-formatting-elements>list of active formatting
elements</a>.</p>
<p><a href=#insert-an-html-element>Insert an HTML element</a> for the token. <a href=#push-onto-the-list-of-active-formatting-elements>Push
onto the list of active formatting elements</a> that
element.</p>

</dd>

<a href=#reconstruct-the-active-formatting-elements>reconstruct the active formatting elements</a>, if
any.</p>

<p><a href=#insert-an-html-element>Insert an HTML element</a> for the token. Add that
element to the <a href=#list-of-active-formatting-elements>list of active formatting
elements</a>.</p>
<p><a href=#insert-an-html-element>Insert an HTML element</a> for the token. <a href=#push-onto-the-list-of-active-formatting-elements>Push
onto the list of active formatting elements</a> that
element.</p>

</dd>


<li>has the same tag name as the token.</li>

</ul><p>If there is no such node, or, if that node is also in the
<a href=#stack-of-open-elements>stack of open elements</a> but the element is not <a href=#has-an-element-in-scope title="has an element in scope">in scope</a>, then this is a
<a href=#parse-error>parse error</a>; ignore the token, and abort these
steps.</p>
</ul><p>If there is no such node, then abort these steps and instead
act as described in the "any other end tag" entry below.</p>

<p>Otherwise, if there is such a node, but that node is not
in the <a href=#stack-of-open-elements>stack of open elements</a>, then this is a
<a href=#parse-error>parse error</a>; remove the element from the list,
and abort these steps.</p>

<p>Otherwise, if there is such a node, and that node is also in
the <a href=#stack-of-open-elements>stack of open elements</a>, but the element is not
<a href=#has-an-element-in-scope title="has an element in scope">in scope</a>, then this
is a <a href=#parse-error>parse error</a>; ignore the token, and abort these
steps.</p>

<p>Otherwise, there is a <var title="">formatting
element</var> and that element is in <a href=#stack-of-open-elements title="stack of
open elements">the stack</a> and is <a href=#has-an-element-in-scope title="has an
<ul class=domTree><li class=t1><code><a href=#the-html-element-0>html</a></code><ul><li class=t1><code><a href=#the-head-element-0>head</a></code><li class=t1><code><a href=#the-body-element-0>body</a></code><ul><li class=t1><code><a href=#script>script</a></code><ul><li class=t3><code>#text</code>: <span title="">alert(document.URL);</span></ul></ul></ul></ul><p>This second alert will say "http://example.com/inner".</p>


<h5 id=unclosed-formatting-elements><span class=secno>12.2.8.5 </span>Unclosed formatting elements</h5>

<p><i>This section is non-normative.</i></p>

<p>The following markup shows how nested formatting elements (such
as <code><a href=#the-b-element>b</a></code>) get collected and continue to be applied even as
the elements they are contained in are closed, but that excessive
duplicates are thrown away.</p>

<pre>&lt;!DOCTYPE html&gt;
&lt;p&gt;&lt;b class=x&gt;&lt;b class=x&gt;&lt;b&gt;&lt;b class=x&gt;&lt;b class=x&gt;&lt;b&gt;X
&lt;p&gt;X
&lt;p&gt;&lt;b&gt;&lt;b class=x&gt;&lt;b&gt;X
&lt;p&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;X</pre>

<p>The resulting DOM tree is as follows:</p>

<ul class=domTree><li class=t10>DOCTYPE: <code><a href=#the-html-element-0>html</a></code><li class=t1><code><a href=#the-html-element-0>html</a></code><ul><li class=t1><code><a href=#the-head-element-0>head</a></code><li class=t1><code><a href=#the-body-element-0>body</a></code><ul><li class=t1><code><a href=#the-p-element>p</a></code><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code><ul><li class=t3><code>#text</code>: <span title="">X&#9166;</span></ul></ul></ul></ul></ul></ul></ul><li class=t1><code><a href=#the-p-element>p</a></code><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code><ul><li class=t3><code>#text</code>: <span title="">X&#9166;</span></ul></ul></ul></ul></ul></ul><li class=t1><code><a href=#the-p-element>p</a></code><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code><ul><li class=t1><code><a href=#the-b-element>b</a></code><ul><li class=t1><code><a href=#the-b-element>b</a></code> <span class=t2 title=""><code class="attribute name">class</code>="<code class="attribute value">x</code>"</span><ul><li class=t1><code><a href=#the-b-element>b</a></code><ul><li class=t3><code>#text</code>: <span title="">X&#9166;</span></ul></ul></ul></ul></ul></ul></ul></ul></ul><li class=t1><code><a href=#the-p-element>p</a></code><ul><li class=t3><code>#text</code>: <span title="">X&#9166;</span></ul></ul></ul></ul><p>Note how the second <code><a href=#the-p-element>p</a></code> element in the markup has no
explicit <code><a href=#the-b-element>b</a></code> elements, but in the resulting DOM, up to
three of each kind of formatting element (in this case three
<code><a href=#the-b-element>b</a></code> elements with the class attribute, and two unadorned
<code><a href=#the-b-element>b</a></code> elements) get reconstructed before the element's
"X".</p>

<p>Also note how this means that in the final paragraph only six
<code><a href=#the-b-element>b</a></code> end tags are needed to completely clear the list of
formatting elements, even though nine <code><a href=#the-b-element>b</a></code> start tags have
been seen up to this point.</p>




<h3 id=serializing-html-fragments><span class=secno>12.3 </span>Serializing HTML fragments</h3>

0 comments on commit 42d40e6

Please sign in to comment.
You can’t perform that action at this time.