diff --git a/components/style/values/specified/effects.rs b/components/style/values/specified/effects.rs index cd248224623..7b9ea0c7bb9 100644 --- a/components/style/values/specified/effects.rs +++ b/components/style/values/specified/effects.rs @@ -4,9 +4,9 @@ //! Specified types for CSS values related to effects. -use cssparser::Parser; +use cssparser::{Parser, Token, BasicParseError}; use parser::{Parse, ParserContext}; -use style_traits::{ParseError, StyleParseError}; +use style_traits::{ParseError, StyleParseError, ValueParseError}; #[cfg(not(feature = "gecko"))] use values::Impossible; use values::computed::{Context, NonNegativeNumber as ComputedNonNegativeNumber, ToComputedValue}; @@ -161,9 +161,14 @@ impl Parse for Filter { return Ok(GenericFilter::Url(url)); } } - let function = input.expect_function()?.clone(); + let function = match input.expect_function() { + Ok(f) => f.clone(), + Err(BasicParseError::UnexpectedToken(t)) => + return Err(ValueParseError::InvalidFilter(t.clone()).into()), + Err(e) => return Err(e.into()), + }; input.parse_nested_block(|i| { - try_match_ident_ignore_ascii_case! { function, + match_ignore_ascii_case! { &*function, "blur" => Ok(GenericFilter::Blur((Length::parse_non_negative(context, i)?).into())), "brightness" => Ok(GenericFilter::Brightness(Factor::parse(context, i)?)), "contrast" => Ok(GenericFilter::Contrast(Factor::parse(context, i)?)), @@ -174,6 +179,7 @@ impl Parse for Filter { "saturate" => Ok(GenericFilter::Saturate(Factor::parse(context, i)?)), "sepia" => Ok(GenericFilter::Sepia(Factor::parse(context, i)?)), "drop-shadow" => Ok(GenericFilter::DropShadow(Parse::parse(context, i)?)), + _ => Err(ValueParseError::InvalidFilter(Token::Function(function.clone())).into()), } }) } diff --git a/components/style_traits/lib.rs b/components/style_traits/lib.rs index 0ef1fee83c4..5ceab72427d 100644 --- a/components/style_traits/lib.rs +++ b/components/style_traits/lib.rs @@ -132,6 +132,14 @@ pub enum StyleParseError<'i> { pub enum ValueParseError<'i> { /// An invalid token was encountered while parsing a color value. InvalidColor(Token<'i>), + /// An invalid filter value was encountered. + InvalidFilter(Token<'i>), +} + +impl<'a> From> for ParseError<'a> { + fn from(this: ValueParseError<'a>) -> Self { + StyleParseError::ValueError(this).into() + } } impl<'i> ValueParseError<'i> { diff --git a/ports/geckolib/error_reporter.rs b/ports/geckolib/error_reporter.rs index 98699d6063e..4b0a1ed088a 100644 --- a/ports/geckolib/error_reporter.rs +++ b/ports/geckolib/error_reporter.rs @@ -122,7 +122,8 @@ fn extract_error_param<'a>(err: ParseError<'a>) -> Option> { fn extract_value_error_param<'a>(err: ValueParseError<'a>) -> ErrorString<'a> { match err { - ValueParseError::InvalidColor(t) => ErrorString::UnexpectedToken(t), + ValueParseError::InvalidColor(t) | + ValueParseError::InvalidFilter(t) => ErrorString::UnexpectedToken(t), } } @@ -221,6 +222,7 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> { PropertyDeclarationParseError::InvalidValue(_, ref err))))) => { let prefix = match *err { Some(ValueParseError::InvalidColor(_)) => Some(&b"PEColorNotColor\0"[..]), + Some(ValueParseError::InvalidFilter(_)) => Some(&b"PEExpectedNoneOrURLOrFilterFunction\0"[..]), _ => None, }; return (prefix, b"PEValueParsingError\0", Action::Drop);