W3C home > Mailing lists > Public > www-style@w3.org > January 2008

[CSS 2.1] @charset, @import, and error recovery

From: Justin Rogers <justrog@microsoft.com>
Date: Sat, 26 Jan 2008 14:59:06 -0800
To: "www-style@w3.org" <www-style@w3.org>
Message-ID: <00BD06E707F60B4F9D6A3E75C712209D49A94E5DBF@NA-EXMSG-C104.redmond.corp.microsoft.com>
The rules for @import are very clear, however, when it comes to error recovery, they get a bit muddied and I think the spec could use a bit of clarification.

"Any @import rules must precede all other rules (except the @charset rule, if present)."

Well that is clear. NO other rules are allowed, but what about failed rules? Rules that don't make sense:

@charset "hola"; /* I can ignore this I guess */
@foo { };
@import url(a.css); /* I should be throwing this out, or should I? */

Browsers are inconsistent here. When I read the spec, I want to write something like:

while( AtImport ) { HandleAtImport(); }
while( !EOF ) { HandleRules(); }

The above @foo { }; doesn't allow for that if we are supposed to parse @import up until we find the first successful rule. Because of this inconsistency, some browsers are ignoring tons of stuff at the top of the sheet and still processing imports.

An interesting side note is that I think it is implied clearly in the spec that if you parse an invalid @import rule then you should continue parsing @import's further until you hit some other non import rule. Clarification would be nice though.

For @charset, if you fail to parse it, should you disable @import or should you treat it like it was an @charset anyway so imports aren't disabled, in other words, should the following work or fail:

@charset "foo" bar; /* start with HandleCharSet, fall back to HandleInvalidRuleSet */
@import url(a.css);

Another good one is multiple charset rules. The spec clearly says I can have only one, parsing the second one would technically be a "rule" which should then break the @import logic.

@charset "utf-7";
@charset "oops";
@import url(a.css);

Justin [MSFT]
Received on Saturday, 26 January 2008 22:59:48 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:27:33 UTC