From a13850428ee1d2bd22f585ebb74138f6534839de Mon Sep 17 00:00:00 2001 From: David LeGare Date: Wed, 9 Dec 2015 17:55:12 -0600 Subject: [PATCH] fix(parse-collada): correctly interpret xs:anyURI type Add a new AnyUri type to use for parsing attributes with the xs:anyURI type. Change InstangeGeometry::url to be of type AnyUri to be more correct. BREAKING CHANGES: Any usage of InstanceGeometry::url will be broken now that it is an enum type. --- lib/parse_collada/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/parse_collada/src/lib.rs b/lib/parse_collada/src/lib.rs index 83a8c51..e0ed4a0 100644 --- a/lib/parse_collada/src/lib.rs +++ b/lib/parse_collada/src/lib.rs @@ -616,6 +616,23 @@ collada_element!("animation", Animation => { collada_element!("annotate", Annotate => {}); +#[derive(Debug, Clone)] +pub enum AnyUri { + Local(UriFragment), + External(String), +} + +impl ColladaAttribute for AnyUri { + fn parse(text: &str) -> Result { + if text.starts_with("#") { + let uri_fragment = try!(parse_attrib(text)); + Ok(AnyUri::Local(uri_fragment)) + } else { + Ok(AnyUri::External(String::from(text))) + } + } +} + #[derive(Debug, Clone)] pub enum ArrayElement { Idref(IdrefArray), @@ -945,7 +962,7 @@ collada_element!("instance_effect", InstanceEffect => { }); collada_element!("instance_geometry", InstanceGeometry => { - req attrib "url" => url: String + req attrib "url" => url: AnyUri opt attrib "sid" => sid: String, opt attrib "name" => name: String @@ -1658,7 +1675,7 @@ impl ColladaElement for UpAxis { } #[derive(Debug, Clone)] -pub struct UriFragment(String); +pub struct UriFragment(pub String); impl Deref for UriFragment { type Target = String;