stylo: Update rust-cssparser; extract more specific error types when reporting (bug 1352669).

This commit is contained in:
Josh Matthews 2017-07-06 13:59:31 -04:00
parent a08371e8eb
commit 0b43d0072c
21 changed files with 318 additions and 80 deletions

View file

@ -38,7 +38,7 @@ bitflags = "0.7"
bit-vec = "0.4.3"
byteorder = "1.0"
cfg-if = "0.1.0"
cssparser = "0.16.1"
cssparser = "0.17.0"
encoding = {version = "0.2", optional = true}
euclid = "0.15"
fnv = "1.0"

View file

@ -280,10 +280,10 @@ fn parse_declaration_value_block<'i, 't>
}
token.serialization_type()
}
Token::BadUrl =>
return Err(StyleParseError::BadUrlInDeclarationValueBlock.into()),
Token::BadString =>
return Err(StyleParseError::BadStringInDeclarationValueBlock.into()),
Token::BadUrl(u) =>
return Err(StyleParseError::BadUrlInDeclarationValueBlock(u).into()),
Token::BadString(s) =>
return Err(StyleParseError::BadStringInDeclarationValueBlock(s).into()),
Token::CloseParenthesis =>
return Err(StyleParseError::UnbalancedCloseParenthesisInDeclarationValueBlock.into()),
Token::CloseSquareBracket =>

View file

@ -76,8 +76,8 @@ impl<'a> ContextualParseError<'a> {
Token::ParenthesisBlock => format!("parenthesis ("),
Token::SquareBracketBlock => format!("square bracket ["),
Token::CurlyBracketBlock => format!("curly bracket {{"),
Token::BadUrl => format!("bad url parse error"),
Token::BadString => format!("bad string parse error"),
Token::BadUrl(ref _u) => format!("bad url parse error"),
Token::BadString(ref _s) => format!("bad string parse error"),
Token::CloseParenthesis => format!("unmatched close parenthesis"),
Token::CloseSquareBracket => format!("unmatched close square bracket"),
Token::CloseCurlyBracket => format!("unmatched close curly bracket"),
@ -88,11 +88,11 @@ impl<'a> ContextualParseError<'a> {
match *err {
CssParseError::Basic(BasicParseError::UnexpectedToken(ref t)) =>
format!("found unexpected {}", token_to_str(t)),
CssParseError::Basic(BasicParseError::ExpectedToken(ref t)) =>
format!("expected {}", token_to_str(t)),
CssParseError::Basic(BasicParseError::EndOfInput) =>
format!("unexpected end of input"),
CssParseError::Basic(BasicParseError::AtRuleInvalid) =>
CssParseError::Basic(BasicParseError::AtRuleInvalid(ref i)) =>
format!("@ rule invalid: {}", i),
CssParseError::Basic(BasicParseError::AtRuleBodyInvalid) =>
format!("@ rule invalid"),
CssParseError::Basic(BasicParseError::QualifiedRuleInvalid) =>
format!("qualified rule invalid"),

View file

@ -908,10 +908,17 @@ pub fn parse_one_declaration_into(declarations: &mut SourcePropertyDeclaration,
parsing_mode,
quirks_mode);
let mut input = ParserInput::new(input);
Parser::new(&mut input).parse_entirely(|parser| {
let mut parser = Parser::new(&mut input);
let start = parser.position();
parser.parse_entirely(|parser| {
PropertyDeclaration::parse_into(declarations, id, &context, parser)
.map_err(|e| e.into())
}).map_err(|_| ())
}).map_err(|err| {
let end = parser.position();
let error = ContextualParseError::UnsupportedPropertyDeclaration(
parser.slice(start..end), err);
log_css_error(&mut parser, start, error, &context);
})
}
/// A struct to parse property declarations.

View file

@ -37,7 +37,8 @@ use properties::animated_properties::AnimatableLonghand;
use selectors::parser::SelectorParseError;
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
use shared_lock::StylesheetGuards;
use style_traits::{PARSING_MODE_DEFAULT, HasViewportPercentage, ToCss, ParseError, PropertyDeclarationParseError};
use style_traits::{PARSING_MODE_DEFAULT, HasViewportPercentage, ToCss, ParseError};
use style_traits::{PropertyDeclarationParseError, StyleParseError};
use stylesheets::{CssRuleType, MallocSizeOf, MallocSizeOfFn, Origin, UrlExtraData};
#[cfg(feature = "servo")] use values::Either;
use values::generics::text::LineHeight;
@ -1009,7 +1010,7 @@ impl PropertyId {
match static_id(&property_name) {
Some(&StaticId::Longhand(id)) => Ok(PropertyId::Longhand(id)),
Some(&StaticId::Shorthand(id)) => Ok(PropertyId::Shorthand(id)),
None => Err(SelectorParseError::UnexpectedIdent(property_name).into()),
None => Err(StyleParseError::UnknownProperty(property_name).into()),
}
}
@ -1414,7 +1415,7 @@ impl PropertyDeclaration {
Ok(keyword) => DeclaredValueOwned::CSSWideKeyword(keyword),
Err(_) => match ::custom_properties::SpecifiedValue::parse(context, input) {
Ok(value) => DeclaredValueOwned::Value(value),
Err(_) => return Err(PropertyDeclarationParseError::InvalidValue),
Err(_) => return Err(PropertyDeclarationParseError::InvalidValue(name.to_string())),
}
};
declarations.push(PropertyDeclaration::Custom(name, value));
@ -1442,7 +1443,7 @@ impl PropertyDeclaration {
declarations.push(value);
Ok(())
},
Err(_) => Err(PropertyDeclarationParseError::InvalidValue),
Err(_) => Err(PropertyDeclarationParseError::InvalidValue("${property.ident}".into())),
}
% else:
Err(PropertyDeclarationParseError::UnknownProperty)
@ -1482,7 +1483,7 @@ impl PropertyDeclaration {
},
Err(_) => {
shorthands::${shorthand.ident}::parse_into(declarations, context, input)
.map_err(|_| PropertyDeclarationParseError::InvalidValue)
.map_err(|_| PropertyDeclarationParseError::InvalidValue("${shorthand.ident}".into()))
}
}
}

View file

@ -7,7 +7,7 @@
use {Namespace, Prefix};
use counter_style::{parse_counter_style_body, parse_counter_style_name};
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
use cssparser::{CompactCowStr, SourceLocation};
use cssparser::{CompactCowStr, SourceLocation, BasicParseError};
use error_reporting::ContextualParseError;
use font_face::parse_font_face_block;
use media_queries::{parse_media_query_list, MediaList};
@ -184,7 +184,13 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
self.state = State::Namespaces;
let prefix_result = input.try(|input| input.expect_ident());
let url = Namespace::from(Cow::from(input.expect_url_or_string()?));
let maybe_namespace = match input.expect_url_or_string() {
Ok(url_or_string) => url_or_string,
Err(BasicParseError::UnexpectedToken(t)) =>
return Err(StyleParseError::UnexpectedTokenWithinNamespace(t).into()),
Err(e) => return Err(e.into()),
};
let url = Namespace::from(Cow::from(maybe_namespace));
let id = register_namespace(&url)
.map_err(|()| StyleParseError::UnspecifiedError)?;
@ -509,7 +515,7 @@ fn get_location_with_offset(
offset: u64
) -> SourceLocation {
SourceLocation {
line: location.line + offset as u32 - 1,
line: location.line + offset as u32,
column: location.column,
}
}