DOM comments inside a <style> element

Hi there,

[ please note I have set the Reply-To field of this message to ]
[ ; followups _only_ there please ]

I am hitting a consistency issue related to the style element:
if a COMMENT_NODE child containing a valid stylesheet as data is added
as child of an empty style element, non-WebKit browsers don't honour
that stylesheet. Example:

    <style type="text/css">p { color: red; }</style>
    <style id="mystyles" type="text/css"></style>
      var c = document.createComment("p { color: green; }");
    <p>This paragraph should be green</p>

However, the serialization of the test's DOM tree just above after
script's execution will create a document instance containing a
valid and parsed stylesheet since the HTML parsing
rules create an exception if raw text contents of a style element start
with the literal string "<!--"... In the example above, the
serialization of the style element is

   <style id="mystyles" type="text/css"><!--p { color: green; }--></style>

and that is clearly a valid style element that will result in
a green color applied to all paragraphs.

FYI, WebKit-based browsers pass my test [1], others don't.

I think WebKit is right here. For consistency reasons, comments
programmatically added to the children of a <style> element should be
considered as the textual concatenation of "<!--", their textual data
and "-->".


W3C CSS WG, Co-chairman

Received on Monday, 27 December 2010 10:34:38 UTC