diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 9fc1bbfe16b..df8f3988337 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -122,33 +122,32 @@ impl DocumentMatchingFunction { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input - .try(|input| input.expect_function_matching("url-prefix")) - .is_ok() - { - return parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::UrlPrefix); + if let Ok(url) = input.try(|input| CssUrl::parse(context, input)) { + return Ok(DocumentMatchingFunction::Url(url)) } - if input - .try(|input| input.expect_function_matching("domain")) - .is_ok() - { - return parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::Domain); - } - - if input - .try(|input| input.expect_function_matching("regexp")) - .is_ok() - { - return input.parse_nested_block(|input| { - Ok(DocumentMatchingFunction::Regexp( - input.expect_string()?.as_ref().to_owned(), + let location = input.current_source_location(); + let function = input.expect_function()?.clone(); + match_ignore_ascii_case! { &function, + "url-prefix" => { + parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::UrlPrefix) + } + "domain" => { + parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::Domain) + } + "regexp" => { + input.parse_nested_block(|input| { + Ok(DocumentMatchingFunction::Regexp( + input.expect_string()?.as_ref().to_owned(), + )) + }) + } + _ => { + Err(location.new_custom_error( + StyleParseErrorKind::UnexpectedFunction(function.clone()) )) - }); + } } - - let url = CssUrl::parse(context, input)?; - Ok(DocumentMatchingFunction::Url(url)) } #[cfg(feature = "gecko")]