From 1c3a701d2e5847586cdadaebc18f6482c721878a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 30 Dec 2017 16:48:07 +0100 Subject: [PATCH] element: Fix element name comparison in from_reader quick-xml's Events seem to always return prefixed names, and the from_reader function, when comparing name of the pop-ed element, and received event element, was using the unprefixed name to compare. --- src/element.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/element.rs b/src/element.rs index e398d40..4494d41 100644 --- a/src/element.rs +++ b/src/element.rs @@ -191,6 +191,11 @@ impl Element { &self.name } + /// Returns a reference to the prefix of this element. + pub fn prefix(&self) -> Option { + self.prefix.clone() + } + /// Returns a reference to the namespace of this element, if it has one, else `None`. pub fn ns(&self) -> Option { self.namespaces.get(&self.prefix) @@ -318,7 +323,11 @@ impl Element { } let elem = stack.pop().unwrap(); if let Some(to) = stack.last_mut() { - if elem.name().as_bytes() != e.name() { + let name = match elem.prefix() { + Some(ref prefix) => format!("{}:", prefix.clone()), + None => String::from(""), + } + elem.name(); + if name.as_bytes() != e.name() { bail!(ErrorKind::InvalidElementClosed); } to.append_child(elem);