mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Report more invalid selectors (bug 1384216).
This commit is contained in:
parent
9a7cceb0a1
commit
4016371e1d
2 changed files with 19 additions and 6 deletions
|
@ -50,9 +50,6 @@ fn to_ascii_lowercase(s: &str) -> Cow<str> {
|
||||||
pub enum SelectorParseError<'i, T> {
|
pub enum SelectorParseError<'i, T> {
|
||||||
PseudoElementInComplexSelector,
|
PseudoElementInComplexSelector,
|
||||||
NoQualifiedNameInAttributeSelector(Token<'i>),
|
NoQualifiedNameInAttributeSelector(Token<'i>),
|
||||||
TooManyCompoundSelectorComponentsInNegation,
|
|
||||||
NegationSelectorComponentNotNamespace,
|
|
||||||
NegationSelectorComponentNotLocalName,
|
|
||||||
EmptySelector,
|
EmptySelector,
|
||||||
DanglingCombinator,
|
DanglingCombinator,
|
||||||
NonSimpleSelectorInNegation,
|
NonSimpleSelectorInNegation,
|
||||||
|
@ -67,6 +64,8 @@ pub enum SelectorParseError<'i, T> {
|
||||||
BadValueInAttr(Token<'i>),
|
BadValueInAttr(Token<'i>),
|
||||||
InvalidQualNameInAttr(Token<'i>),
|
InvalidQualNameInAttr(Token<'i>),
|
||||||
ExplicitNamespaceUnexpectedToken(Token<'i>),
|
ExplicitNamespaceUnexpectedToken(Token<'i>),
|
||||||
|
ClassNeedsIdent(Token<'i>),
|
||||||
|
EmptyNegation,
|
||||||
Custom(T),
|
Custom(T),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1446,13 +1445,19 @@ fn parse_negation<'i, 't, P, E, Impl>(parser: &P,
|
||||||
|
|
||||||
// Get exactly one simple selector. The parse logic in the caller will verify
|
// Get exactly one simple selector. The parse logic in the caller will verify
|
||||||
// that there are no trailing tokens after we're done.
|
// that there are no trailing tokens after we're done.
|
||||||
if !parse_type_selector(parser, input, &mut sequence)? {
|
let is_type_sel = match parse_type_selector(parser, input, &mut sequence) {
|
||||||
|
Ok(result) => result,
|
||||||
|
Err(ParseError::Basic(BasicParseError::EndOfInput)) =>
|
||||||
|
return Err(SelectorParseError::EmptyNegation.into()),
|
||||||
|
Err(e) => return Err(e.into()),
|
||||||
|
};
|
||||||
|
if !is_type_sel {
|
||||||
match parse_one_simple_selector(parser, input, /* inside_negation = */ true)? {
|
match parse_one_simple_selector(parser, input, /* inside_negation = */ true)? {
|
||||||
Some(SimpleSelectorParseResult::SimpleSelector(s)) => {
|
Some(SimpleSelectorParseResult::SimpleSelector(s)) => {
|
||||||
sequence.push(s);
|
sequence.push(s);
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
return Err(ParseError::Custom(SelectorParseError::EmptySelector));
|
return Err(ParseError::Custom(SelectorParseError::EmptyNegation));
|
||||||
},
|
},
|
||||||
Some(SimpleSelectorParseResult::PseudoElement(_)) => {
|
Some(SimpleSelectorParseResult::PseudoElement(_)) => {
|
||||||
return Err(ParseError::Custom(SelectorParseError::NonSimpleSelectorInNegation));
|
return Err(ParseError::Custom(SelectorParseError::NonSimpleSelectorInNegation));
|
||||||
|
@ -1622,7 +1627,7 @@ fn parse_one_simple_selector<'i, 't, P, E, Impl>(parser: &P,
|
||||||
let class = Component::Class(class.as_ref().into());
|
let class = Component::Class(class.as_ref().into());
|
||||||
Ok(Some(SimpleSelectorParseResult::SimpleSelector(class)))
|
Ok(Some(SimpleSelectorParseResult::SimpleSelector(class)))
|
||||||
}
|
}
|
||||||
ref t => Err(ParseError::Basic(BasicParseError::UnexpectedToken(t.clone()))),
|
ref t => Err(SelectorParseError::ClassNeedsIdent(t.clone()).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Token::SquareBracketBlock) => {
|
Ok(Token::SquareBracketBlock) => {
|
||||||
|
|
|
@ -255,6 +255,7 @@ fn extract_error_params<'a>(err: ParseError<'a>) -> Option<ErrorParams<'a>> {
|
||||||
CssParseError::Custom(SelectorParseError::ExplicitNamespaceUnexpectedToken(t)) |
|
CssParseError::Custom(SelectorParseError::ExplicitNamespaceUnexpectedToken(t)) |
|
||||||
CssParseError::Custom(SelectorParseError::PseudoElementExpectedIdent(t)) |
|
CssParseError::Custom(SelectorParseError::PseudoElementExpectedIdent(t)) |
|
||||||
CssParseError::Custom(SelectorParseError::NoIdentForPseudo(t)) |
|
CssParseError::Custom(SelectorParseError::NoIdentForPseudo(t)) |
|
||||||
|
CssParseError::Custom(SelectorParseError::ClassNeedsIdent(t)) |
|
||||||
CssParseError::Custom(SelectorParseError::PseudoElementExpectedColon(t)) =>
|
CssParseError::Custom(SelectorParseError::PseudoElementExpectedColon(t)) =>
|
||||||
(None, Some(ErrorString::UnexpectedToken(t))),
|
(None, Some(ErrorString::UnexpectedToken(t))),
|
||||||
|
|
||||||
|
@ -268,6 +269,9 @@ fn extract_error_params<'a>(err: ParseError<'a>) -> Option<ErrorParams<'a>> {
|
||||||
CssParseError::Custom(SelectorParseError::DanglingCombinator) =>
|
CssParseError::Custom(SelectorParseError::DanglingCombinator) =>
|
||||||
(None, None),
|
(None, None),
|
||||||
|
|
||||||
|
CssParseError::Custom(SelectorParseError::EmptyNegation) =>
|
||||||
|
(None, Some(ErrorString::Snippet(")".into()))),
|
||||||
|
|
||||||
err => match extract_error_param(err) {
|
err => match extract_error_param(err) {
|
||||||
Some(e) => (Some(e), None),
|
Some(e) => (Some(e), None),
|
||||||
None => return None,
|
None => return None,
|
||||||
|
@ -368,6 +372,10 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
|
||||||
Some(&b"PEPseudoClassArgNotIdent\0"[..]),
|
Some(&b"PEPseudoClassArgNotIdent\0"[..]),
|
||||||
CssParseError::Custom(SelectorParseError::PseudoElementExpectedIdent(_)) =>
|
CssParseError::Custom(SelectorParseError::PseudoElementExpectedIdent(_)) =>
|
||||||
Some(&b"PEPseudoSelBadName\0"[..]),
|
Some(&b"PEPseudoSelBadName\0"[..]),
|
||||||
|
CssParseError::Custom(SelectorParseError::ClassNeedsIdent(_)) =>
|
||||||
|
Some(&b"PEClassSelNotIdent\0"[..]),
|
||||||
|
CssParseError::Custom(SelectorParseError::EmptyNegation) =>
|
||||||
|
Some(&b"PENegationBadArg\0"[..]),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
return (prefix, b"PEBadSelectorRSIgnored\0", Action::Nothing);
|
return (prefix, b"PEBadSelectorRSIgnored\0", Action::Nothing);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue