W3C home > Mailing lists > Public > www-style@w3.org > December 2010

DOM comments inside a <style> element

From: Daniel Glazman <daniel.glazman@disruptive-innovations.com>
Date: Mon, 27 Dec 2010 11:33:52 +0100
Message-ID: <4D186B90.9080206@disruptive-innovations.com>
To: "www-style@w3.org" <www-style@w3.org>, HTML WG <public-html@w3.org>
Hi there,

[ please note I have set the Reply-To field of this message to ]
[ public-html@w3.org ; 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>
    <script>
      var c = document.createComment("p { color: green; }");
      document.getElementById("mystyles).appendChild(c);
    <script>
    <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 "-->".

[1] http://disruptive-innovations.com/zoo/csswg/test-style-elt-20101227.html

</Daniel>
--
W3C CSS WG, Co-chairman
Received on Monday, 27 December 2010 10:34:38 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:35 GMT