[librsvg: 4/43] Return a ParseError from the basic parse_property()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 4/43] Return a ParseError from the basic parse_property()
- Date: Sat, 21 Dec 2019 02:29:50 +0000 (UTC)
commit 759769b5d1d7dddfca99688d2831a71bb57a02fd
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Dec 19 19:01:57 2019 -0600
Return a ParseError from the basic parse_property()
rsvg_internals/src/css.rs | 2 +-
rsvg_internals/src/properties.rs | 77 +++++++++++++++++++++++++++++++++++-----
2 files changed, 69 insertions(+), 10 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index c59894f7..607f4dda 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -123,7 +123,7 @@ impl<'i> DeclarationParser<'i> for DeclParser {
) -> Result<Declaration, CssParseError<'i>> {
let prop_name = QualName::new(None, ns!(svg), LocalName::from(name.as_ref()));
let property =
- parse_property(&prop_name, input, true).map_err(|e| input.new_custom_error(e))?;
+ parse_property(&prop_name, input, true).map_err(|_|
input.new_custom_error(ValueErrorKind::parse_error("parse error")))?;
let important = input.try_parse(parse_important).is_ok();
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 7519c9a6..ea5227ef 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -1,6 +1,8 @@
//! CSS properties, specified values, computed values.
-use cssparser::{self, DeclarationListParser, Parser, ParserInput};
+use cssparser::{
+ self, BasicParseErrorKind, DeclarationListParser, ParseErrorKind, Parser, ParserInput, ToCss,
+};
use markup5ever::{expanded_name, local_name, namespace_url, ns, QualName};
use std::collections::HashSet;
@@ -225,7 +227,7 @@ pub struct ComputedValues {
}
#[cfg_attr(rustfmt, rustfmt_skip)]
-pub fn parse_property(prop_name: &QualName, input: &mut Parser, accept_shorthands: bool) ->
Result<ParsedProperty, ValueErrorKind> {
+pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, accept_shorthands: bool) ->
Result<ParsedProperty, ParseError<'i>> {
// please keep these sorted
match prop_name.expanded() {
expanded_name!(svg "baseline-shift") =>
@@ -298,7 +300,7 @@ pub fn parse_property(prop_name: &QualName, input: &mut Parser, accept_shorthand
if accept_shorthands {
Ok(ParsedProperty::Marker(parse_input(input)?))
} else {
- Err(ValueErrorKind::UnknownProperty)
+ Err(ValueErrorKind::UnknownProperty)?
}
}
@@ -371,7 +373,7 @@ pub fn parse_property(prop_name: &QualName, input: &mut Parser, accept_shorthand
expanded_name!(svg "writing-mode") =>
Ok(ParsedProperty::WritingMode(parse_input(input)?)),
- _ => Err(ValueErrorKind::UnknownProperty)
+ _ => Err(ValueErrorKind::UnknownProperty)?
}
}
@@ -535,19 +537,76 @@ impl SpecifiedValues {
Ok(prop) => self.set_parsed_property(&prop),
// not a presentation attribute
- Err(ValueErrorKind::UnknownProperty) => (),
+ Err(ParseError::V(ValueErrorKind::UnknownProperty)) => (),
- Err(e) => {
- // https://www.w3.org/TR/CSS2/syndata.html#unsupported-values
- // Ignore illegal values; don't set the whole node to be in error in that case.
+ // https://www.w3.org/TR/CSS2/syndata.html#unsupported-values
+ // For all the following cases, ignore illegal values; don't set the whole node to
+ // be in error in that case.
+ Err(ParseError::V(v)) => {
+ rsvg_log!(
+ "(ignoring invalid presentation attribute {:?}\n \
+ value=\"{}\"\n \
+ {})",
+ attr.expanded(),
+ value,
+ v
+ );
+ }
+
+ Err(ParseError::P(CssParseError {
+ kind: ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken(ref t)),
+ ..
+ })) => {
+ let mut tok = String::new();
+
+ t.to_css(&mut tok).unwrap(); // FIXME: what do we do with a fmt::Error?
+ rsvg_log!(
+ "(ignoring invalid presentation attribute {:?}\n \
+ value=\"{}\"\n \
+ unexpected token '{}')",
+ attr.expanded(),
+ value,
+ tok,
+ );
+ }
+
+ Err(ParseError::P(CssParseError {
+ kind: ParseErrorKind::Basic(BasicParseErrorKind::EndOfInput),
+ ..
+ })) => {
+ rsvg_log!(
+ "(ignoring invalid presentation attribute {:?}\n \
+ value=\"{}\"\n \
+ unexpected end of input)",
+ attr.expanded(),
+ value,
+ );
+ }
+
+ Err(ParseError::P(CssParseError {
+ kind: ParseErrorKind::Basic(_),
+ ..
+ })) => {
+ rsvg_log!(
+ "(ignoring invalid presentation attribute {:?}\n \
+ value=\"{}\"\n \
+ unexpected error)",
+ attr.expanded(),
+ value,
+ );
+ }
+ Err(ParseError::P(CssParseError {
+ kind: ParseErrorKind::Custom(ref v),
+ ..
+ })) => {
rsvg_log!(
"(ignoring invalid presentation attribute {:?}\n \
value=\"{}\"\n \
{})",
attr.expanded(),
value,
- e
+ v
);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]