#934 Misplaced closing conditional comment error

open
nobody
None
5
2010-10-29
2010-10-29
Andrew Murdoch
No

Hi,

I found this in JTidy originaly and tested the same file with HTML Tidy and the error persisted.

I found the particular senario on http://whatsmyuseragent.com/ where a conditional comment is wrapped around another comment like this.

<![endif]-->
<!--[if IE 7]>
<style type="text/css">
<!--
#NavBar ul {
top: -51px;
}
!-->
</style>
<![endif]-->

This mean's that technically the closing </style> is uncommented and the <![endif]--> is misplaced because the close of the inner comment actually closes the outer comment too.

When JTidy encounters this it warns about the misplaced closing style tag as you would expect.
"line 56 column -3 - Warning: discarding unexpected </style>"

However the resulting dom is empty after the commented style tag apart from an empty body tag ... the outputted html is like this:

However the resulting dom is empty after the commented style tag apart from an empty body tag ... the outputted html is like this, notice just <body/> with no children despite the source file having children:

[ .... top of document ... ]

<![endif]--><!--[if IE 7]>
<style type="text/css">
<!==
#NavBar ul {
top: -51px;
}
!--></head><body/></html>

Discussion

  • Andrew Murdoch
    Andrew Murdoch
    2010-10-29

    The html file that causes the error

     
    Attachments