The default bug view has changed. See this FAQ.

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

RESOLVED FIXED in mozilla24

Status

()

Core
CSS Parsing and Computation
RESOLVED FIXED
5 years ago
3 years ago

People

(Reporter: kennyluck, Assigned: dbaron)

Tracking

({dev-doc-complete})

Trunk
mozilla24
dev-doc-complete
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [DocArea=CSS], URL)

Attachments

(4 attachments)

(Reporter)

Description

5 years ago
Created attachment 626116 [details]
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.
(Reporter)

Comment 1

5 years ago
(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.)
(Reporter)

Comment 2

5 years ago
Created attachment 626144 [details] [diff] [review]
Option A - this patch adds some tests for the current behavior
Assignee: nobody → kennyluck
Status: NEW → ASSIGNED
Attachment #626144 - Flags: review?(dbaron)
(Reporter)

Comment 3

5 years ago
Created attachment 626147 [details] [diff] [review]
Option B - to implement the current spec (my reading)

This is admittedly quite crappy.
(Assignee)

Comment 4

5 years ago
Did you raise this on www-style?  I think that's worth doing.
(Reporter)

Comment 5

5 years ago
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
Keywords: dev-doc-needed
(Assignee)

Comment 6

4 years ago
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.)
(Assignee)

Comment 7

4 years ago
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
(Assignee)

Comment 8

4 years ago
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-
(Assignee)

Updated

4 years ago
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)

Comment 9

4 years ago
Minutes of decision at http://lists.w3.org/Archives/Public/www-style/2013May/0783.html
(Assignee)

Updated

4 years ago
Assignee: kennyluck → dbaron
(Assignee)

Comment 10

4 years ago
Created attachment 763128 [details] [diff] [review]
Reject uses of reserved 'not', 'only', 'and', and 'or' as a media type.
Attachment #763128 - Flags: review?(cam)
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+
(Assignee)

Comment 12

4 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/68eed79362f7
https://hg.mozilla.org/mozilla-central/rev/68eed79362f7
Status: ASSIGNED → RESOLVED
Last Resolved: 4 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.
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.