diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 53074d9058a..d6c5a9286bd 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -409,11 +409,12 @@ impl Expression { // If there's no colon, this is a media query of the form // '()', that is, there's no value specified. // - // FIXME(emilio): We need to check for range operators too here when - // we support them, see: - // - // https://drafts.csswg.org/mediaqueries/#mq-ranges + // Gecko doesn't allow ranged expressions without a value, so just + // reject them here too. if input.try(|i| i.expect_colon()).is_err() { + if range != nsMediaExpression_Range::eEqual { + return Err(()) + } return Ok(Expression::new(feature, None, range)); } diff --git a/components/style/media_queries.rs b/components/style/media_queries.rs index e9336515e9c..8a50282682b 100644 --- a/components/style/media_queries.rs +++ b/components/style/media_queries.rs @@ -56,10 +56,10 @@ impl ToCss for Qualifier { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - Qualifier::Not => write!(dest, "not"), - Qualifier::Only => write!(dest, "only"), - } + dest.write_str(match *self { + Qualifier::Not => "not", + Qualifier::Only => "only", + }) } } @@ -152,15 +152,26 @@ pub enum MediaQueryType { } impl MediaQueryType { - fn parse(ident: &str) -> Self { + fn parse(ident: &str) -> Result { if ident.eq_ignore_ascii_case("all") { - return MediaQueryType::All; + return Ok(MediaQueryType::All); } - match MediaType::parse(ident) { + // From https://drafts.csswg.org/mediaqueries/#mq-syntax: + // + // The production does not include the keywords only, + // not, and, and or. + if ident.eq_ignore_ascii_case("not") || + ident.eq_ignore_ascii_case("or") || + ident.eq_ignore_ascii_case("and") || + ident.eq_ignore_ascii_case("only") { + return Err(()) + } + + Ok(match MediaType::parse(ident) { Some(media_type) => MediaQueryType::Known(media_type), None => MediaQueryType::Unknown(Atom::from(ident)), - } + }) } fn matches(&self, other: MediaType) -> bool { @@ -207,7 +218,7 @@ impl MediaQuery { }; let media_type = match input.try(|input| input.expect_ident()) { - Ok(ident) => MediaQueryType::parse(&*ident), + Ok(ident) => try!(MediaQueryType::parse(&*ident)), Err(()) => { // Media type is only optional if qualifier is not specified. if qualifier.is_some() {