Report unknown pseudos (bug 1384216).

This commit is contained in:
Josh Matthews 2017-08-28 17:19:28 -07:00
parent f94612cfeb
commit 8e20a6a110
3 changed files with 24 additions and 15 deletions

View file

@ -58,7 +58,7 @@ pub enum SelectorParseError<'i, T> {
UnexpectedTokenInAttributeSelector,
PseudoElementExpectedColon,
PseudoElementExpectedIdent,
UnsupportedPseudoClass,
UnsupportedPseudoClassOrElement(CowRcStr<'i>),
UnexpectedIdent(CowRcStr<'i>),
ExpectedNamespace(CowRcStr<'i>),
Custom(T),
@ -136,7 +136,7 @@ pub trait Parser<'i> {
fn parse_non_ts_pseudo_class(&self, name: CowRcStr<'i>)
-> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass,
ParseError<'i, SelectorParseError<'i, Self::Error>>> {
Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name)))
Err(ParseError::Custom(SelectorParseError::UnsupportedPseudoClassOrElement(name)))
}
fn parse_non_ts_functional_pseudo_class<'t>
@ -144,20 +144,20 @@ pub trait Parser<'i> {
-> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass,
ParseError<'i, SelectorParseError<'i, Self::Error>>>
{
Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name)))
Err(ParseError::Custom(SelectorParseError::UnsupportedPseudoClassOrElement(name)))
}
fn parse_pseudo_element(&self, name: CowRcStr<'i>)
-> Result<<Self::Impl as SelectorImpl>::PseudoElement,
ParseError<'i, SelectorParseError<'i, Self::Error>>> {
Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name)))
Err(ParseError::Custom(SelectorParseError::UnsupportedPseudoClassOrElement(name)))
}
fn parse_functional_pseudo_element<'t>
(&self, name: CowRcStr<'i>, _arguments: &mut CssParser<'i, 't>)
-> Result<<Self::Impl as SelectorImpl>::PseudoElement,
ParseError<'i, SelectorParseError<'i, Self::Error>>> {
Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name)))
Err(ParseError::Custom(SelectorParseError::UnsupportedPseudoClassOrElement(name)))
}
fn default_namespace(&self) -> Option<<Self::Impl as SelectorImpl>::NamespaceUrl> {
@ -1503,9 +1503,9 @@ fn parse_compound_selector<'i, 't, P, E, Impl>(
};
let pseudo_class =
P::parse_non_ts_pseudo_class(parser, name)?;
P::parse_non_ts_pseudo_class(parser, name.clone())?;
if !p.supports_pseudo_class(&pseudo_class) {
return Err(SelectorParseError::UnsupportedPseudoClass.into());
return Err(SelectorParseError::UnsupportedPseudoClassOrElement(name).into());
}
state_selectors.push(Component::NonTSPseudoClass(pseudo_class));
}

View file

@ -308,7 +308,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
keyword: [$(($k_css:expr, $k_name:ident, $k_gecko_type:tt, $k_state:tt, $k_flags:tt),)*]) => {
match_ignore_ascii_case! { &name,
$($css => NonTSPseudoClass::$name,)*
_ => return Err(::selectors::parser::SelectorParseError::UnexpectedIdent(
_ => return Err(::selectors::parser::SelectorParseError::UnsupportedPseudoClassOrElement(
name.clone()).into())
}
}
@ -317,7 +317,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
if self.is_pseudo_class_enabled(&pseudo_class) {
Ok(pseudo_class)
} else {
Err(SelectorParseError::UnexpectedIdent(name).into())
Err(SelectorParseError::UnsupportedPseudoClassOrElement(name).into())
}
}
@ -354,7 +354,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
}
NonTSPseudoClass::MozAny(selectors.into_boxed_slice())
}
_ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
_ => return Err(SelectorParseError::UnsupportedPseudoClassOrElement(name.clone()).into())
}
}
}
@ -362,13 +362,13 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
if self.is_pseudo_class_enabled(&pseudo_class) {
Ok(pseudo_class)
} else {
Err(SelectorParseError::UnexpectedIdent(name).into())
Err(SelectorParseError::UnsupportedPseudoClassOrElement(name).into())
}
}
fn parse_pseudo_element(&self, name: CowRcStr<'i>) -> Result<PseudoElement, ParseError<'i>> {
PseudoElement::from_slice(&name, self.in_user_agent_stylesheet())
.ok_or(SelectorParseError::UnexpectedIdent(name.clone()).into())
.ok_or(SelectorParseError::UnsupportedPseudoClassOrElement(name.clone()).into())
}
fn parse_functional_pseudo_element<'t>(&self, name: CowRcStr<'i>,
@ -392,7 +392,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
return Ok(pseudo);
}
}
Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
Err(SelectorParseError::UnsupportedPseudoClassOrElement(name.clone()).into())
}
fn default_namespace(&self) -> Option<Namespace> {

View file

@ -250,6 +250,9 @@ fn extract_error_params<'a>(err: ParseError<'a>) -> Option<ErrorParams<'a>> {
PropertyDeclarationParseError::InvalidValue(property, Some(e))))) =>
(Some(ErrorString::Snippet(property.into())), Some(extract_value_error_param(e))),
CssParseError::Custom(SelectorParseError::UnsupportedPseudoClassOrElement(p)) =>
(None, Some(ErrorString::Ident(p))),
err => match extract_error_param(err) {
Some(e) => (Some(e), None),
None => return None,
@ -325,8 +328,14 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
_, CssParseError::Custom(SelectorParseError::Custom(
StyleParseError::UnexpectedTokenWithinNamespace(_)))) =>
(b"PEAtNSUnexpected\0", Action::Nothing),
ContextualParseError::InvalidRule(..) =>
(b"PEBadSelectorRSIgnored\0", Action::Nothing),
ContextualParseError::InvalidRule(_, ref err) => {
let prefix = match *err {
CssParseError::Custom(SelectorParseError::UnsupportedPseudoClassOrElement(_)) =>
Some(&b"PEPseudoSelUnknown\0"[..]),
_ => None,
};
return (prefix, b"PEBadSelectorRSIgnored\0", Action::Nothing);
}
ContextualParseError::UnsupportedRule(..) =>
(b"PEDeclDropped\0", Action::Nothing),
ContextualParseError::UnsupportedViewportDescriptorDeclaration(..) |