Closed Bug 757554 Opened 12 years ago Closed 11 years ago

media query parsing should reject all uses of "not", "only", "and", and "or" as media_type

Categories

(Core :: CSS Parsing and Computation, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla24

People

(Reporter: kennyluck, Assigned: dbaron)

References

()

Details

(Keywords: dev-doc-complete, Whiteboard: [DocArea=CSS])

Attachments

(4 files)

Attached file test case
The rule-based syntax in the spec

  # media_query
  #  : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*

has the interesting (boring?) consequence that media_type allows "only" and "not", which means that, according to the formal grammar, a small amount of backtracking (not sure if I am using the right word here) is required. I see three options to address this spec-implementation mismatch.

A. Ask spec to change to match what Firefox implements.

I'm pretty sure that other browsers do what Firefox does here (but I'll attach testing results in a minute). Also, if this section is rewritten in a state-machine-based approach, it is likely to be what's implemented.

B. Change our implementation to accept "only" and "not" as media type.

C. Change the spec and the implementation to disallow "and" as media type.

I am opposed to this as it requires redundant check to make sure the media type isn't "and".


The effect of this is only observable via CSSOM.
(In reply to Kang-Hao (Kenny) Lu [:kennyluck] from comment #0)
> A. Ask spec to change to match what Firefox implements.

I forgot to mention that what Firefox does currently is that it disallows "and" and "only" as media type when it is *not* preceded by "and" or "not". 
 
> I'm pretty sure that other browsers do what Firefox does here (but I'll
> attach testing results in a minute). 

So IE9 implements what Firefox does. Opera12alpha and Chromium nightly implement C. (The test case doesn't work for Chromium because it doesn't seem to parse <style> with @media that doesn't match :( and also it doesn't implement the "Malformed media query" => "drop until ','" rule :(. A dangling "and" is dropped along with the whole at-rule.)
Assignee: nobody → kennyluck
Status: NEW → ASSIGNED
Attachment #626144 - Flags: review?(dbaron)
This is admittedly quite crappy.
Did you raise this on www-style?  I think that's worth doing.
Yes. Florian's opinion[1] seems to be B. (for which I have a patch too), but using author's point of view for these kinds of corner situations doesn't make sense to me...

I am not eager to pursue any way so I'll let you decide what to do here. We might as well just postpone this until someone bothers to submit a testcase. 

[1] http://lists.w3.org/Archives/Public/www-style/2012May/0955
I think my preference is actually option D:

http://lists.w3.org/Archives/Public/www-style/2013May/0658.html


But I think this is relatively low priority, and we should wait for the spec to settle before moving.

(Sorry to take so long to get to this, again.)
The CSS WG resolved in yesterday's teleconference:
http://krijnhoetmer.nl/irc-logs/css/20130529#l-326 (minutes soon, hopefully)
to accept my proposal (D) in http://lists.w3.org/Archives/Public/www-style/2013May/0658.html
Comment on attachment 626144 [details] [diff] [review]
Option A - this patch adds some tests for the current behavior

That means these two tests:

>+  query_should_be_parseable("and");
>+  query_should_be_parseable("not not");

and this test:

>+  query_should_be_parseable("and and (orientation)");

are no longer correct, and code changes are required.  (Should be 'not'.)

Are you interested in fixing the code here, or should I?
Attachment #626144 - Flags: review?(dbaron) → review-
Summary: Decide whether media query parsing should accept "not", "only" and "and" as media_type → media query parsing should reject all uses of "not", "only", "and", and "or" as media_type
Assignee: kennyluck → dbaron
Comment on attachment 763128 [details] [diff] [review]
Reject uses of reserved 'not', 'only', 'and', and 'or' as a media type.

Review of attachment 763128 [details] [diff] [review]:
-----------------------------------------------------------------

r=me
Attachment #763128 - Flags: review?(cam) → review+
https://hg.mozilla.org/mozilla-central/rev/68eed79362f7
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
Whiteboard: [DocArea=CSS]
Doc updated:
https://developer.mozilla.org/en-US/Firefox/Releases/24

I don't think it is worth a mention in the main text.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: