This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 9463 - Parsing error of @media in CSS2 (should discard invalid statements and resume at the next one)
Summary: Parsing error of @media in CSS2 (should discard invalid statements and resume...
Status: NEW
Alias: None
Product: CSSValidator
Classification: Unclassified
Component: Parser (show other bugs)
Version: CSS Validator
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: This bug has no owner yet - up for the taking
QA Contact: qa-dev tracking
URL: http://jigsaw.w3.org/css-validator/va...
Whiteboard:
Keywords: media
Depends on:
Blocks:
 
Reported: 2010-04-09 10:01 UTC by Alexandre Alapetite
Modified: 2011-10-31 14:34 UTC (History)
1 user (show)

See Also:


Attachments

Description Alexandre Alapetite 2010-04-09 10:01:34 UTC
Hello,
This bug is a CSS2 parsing error, and has a little relation to CSS3 media-queries.

An @media rule specifies the target media types (separated by commas) of a set of statements (delimited by curly braces). Invalid statements must be ignored.
http://www.w3.org/TR/CSS21/media.html#at-media-rule

@media statement1, statement2, statement3 { ... }

Currently the CSS validator will wrongly discard the whole @media rule if one of the statements is invalid, for instance a statement like "this is an error" containing multiple spaces (side note: this is used by CSS3).

== Example ==

@media handheld, only screen and (color)
{
	body
	{
		color:blue;
	}
}

We know that the statement "only screen and (color)" is invalid in CSS2 and should be discarded, but the other statement "handheld" is valid in CSS2 and should be kept.

The CSS Validator returns:

1	unrecognized media only
1	Parse Error screen and (color) { body { color:blue; } } 
@media handheld

The modified CSS stylesheet returned by the validator is invalid, and does not contain the body of @media handheld { ... }

Please note that the example is taken from CSS3 to be relevant, but as far as CSS2 is concerned, it should work just like "@media handheld, some invalid statement, another invalid statement { ... }".

== See also ==

CSS3 media-queries:
http://www.w3.org/TR/css3-mediaqueries/#error-handling

Best regards,
Alexandre
http://alexandre.alapetite.fr
Comment 1 Yves Lafon 2011-10-31 14:34:47 UTC
From CSS2:
<<
@media and @import rules with unknown media types (that are nonetheless valid identifiers) are treated as if the unknown media types are not present. If an @media/@import rule contains a malformed media type (not an identifier) then the statement is invalid. 
>>
In that case, 'only screen and (color)' is not a valid identifier.
However, the bug still stands for '@media print, foo' as erors should be reported but validation should continue.