Commit d7be8d47 authored by Federico Mena Quintero's avatar Federico Mena Quintero Committed by Federico Mena Quintero

(#320) - Parse XmlLang as an identifier, not a CSS string

CSS strings are quoted, like "foo".  Our type for the xml:lang
attribute was being parsed as a CSS string, so an attribute like

  xml:lang="es"

would be parsed incorrectly, as the inner string would have had to be

  xml:lang="'es'"

So, we parse this attribute as an identifier now.

Fixes #320
parent 0a056b87
......@@ -73,20 +73,6 @@ impl Parse for f64 {
}
}
impl Parse for String {
type Data = ();
type Err = ValueErrorKind;
fn parse(parser: &mut Parser<'_, '_>, _: ()) -> Result<String, ValueErrorKind> {
Ok(String::from(
parser
.expect_string()
.map_err(|_| ValueErrorKind::Parse(ParseError::new("expected string")))?
.as_ref(),
))
}
}
/// Parses a `value` string into a type `T`.
///
/// Some value types need some extra `data` to be parsed. This
......
......@@ -144,6 +144,23 @@ macro_rules! make_property {
$parse
};
($computed_values_type: ty,
$name: ident,
default: $default: expr,
inherits_automatically: $inherits_automatically: expr,
newtype: $type: ty,
parse_impl: { $parse: item },
parse_data_type: $parse_data_type: ty
) => {
#[derive(Debug, Clone, PartialEq)]
pub struct $name(pub $type);
impl_default!($name, $name($default));
impl_property!($computed_values_type, $name, $inherits_automatically);
$parse
};
($computed_values_type: ty,
$name: ident,
inherits_automatically: $inherits_automatically: expr,
......
......@@ -1365,10 +1365,34 @@ make_property!(
XmlLang,
default: "".to_string(), // see create_pango_layout()
inherits_automatically: true,
newtype_parse: String,
newtype: String,
parse_impl: {
impl Parse for XmlLang {
type Data = ();
type Err = ValueErrorKind;
fn parse(
parser: &mut Parser<'_, '_>,
_: Self::Data
) -> Result<XmlLang, ValueErrorKind> {
Ok(XmlLang(parser.expect_ident()?.to_string()))
}
}
},
parse_data_type: ()
);
#[cfg(test)]
#[test]
fn parses_xml_lang() {
assert_eq!(
XmlLang::parse_str("es-MX", ()).unwrap(),
XmlLang("es-MX".to_string())
);
assert!(XmlLang::parse_str("", ()).is_err());
}
make_property!(
ComputedValues,
XmlSpace,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment