10

A question was posted on Stack Overflow with this Markdown source:

Write a program to print the following pattern:
* * * * * * * * *
* * * *   * * * *
* * *       * * *
* *           * *
*               *
* *           * *
* * *       * * *
* * * *   * * * *
* * * * * * * * *

Obviously this is incorrectly formatted and it yields a monstrosity of nested lists. But grotesque as it is, there's a bug in the rendered HTML. The HTML has improperly nested <em> tags. IE and Firefox are okay, but in Chrome it leaves italics open for the rest of the page. Here's a screenshot:

Chrome rendering

And here is the questionable HTML:

<p><ul>
<li><ul>
<li><ul>
<li><ul>
<li><ul>
<li><ul>
<li><ul>
<li><em></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
<li><ul>
<li><ul>
<li><ul>
<li><ul>
<li></em></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
<li><ul>
<li><ul>
<li><em></li>
</ul></li>
</ul></li>
<li></em></li>
<li><ul>
<li><ul>
<li><em></li>
</ul></li>
</ul></li>
<li><ul>
<li><ul>
<li><ul>
<li><ul>
<li></em></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
<li><ul>
<li><ul>
<li><ul>
<li><ul>
<li><ul>
<li><ul>
<li>*
<hr></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></li>
</ul></p>
13

(This isn't a "this is fixed" answer; I'm just describing the problem for now).

I learned something new today. Look at HTMLTreeBuilder.cpp in the Chromium source and find the method called callTheAdoptionAgency. I'm serious.

The algorithm that checks what formatting element is closed by a closing HTML tag list limited to a certain search depth for performance reasons. And thus when a closing </em> appears deeply nested inside nine <ul> and <li> elements, the browser will essentially ignore it. Our tag balancer does not have this restriction though, so it thinks the </em> is correctly closed.

These depth restrictions are actually described in the spec, so we can't really blame Chrome for this. Then again, this spec also says this:

When the user agent is to apply the rules for the "in body" insertion mode, the user agent must handle the token as follows: [...]

↪ An end tag whose tag name is "sarcasm"
           Take a deep breath, then act as described in the "any other end tag" entry below.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .