From 3928c7cc5170a529dfb5882b8131457201a41ef2 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Fri, 20 Dec 2019 23:54:26 -0500 Subject: [PATCH] Reject empty text nodes --- core/src/xml/document.rs | 8 ++++++-- core/src/xml/tests.rs | 13 ------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/core/src/xml/document.rs b/core/src/xml/document.rs index b3aaf0b8a..e464441f5 100644 --- a/core/src/xml/document.rs +++ b/core/src/xml/document.rs @@ -64,11 +64,15 @@ impl<'gc> XMLDocument<'gc> { } Event::Text(bt) => { let child = XMLNode::text_from_text_event(mc, bt)?; - document.add_child_to_tree(mc, &mut open_tags, child)?; + if child.node_value().as_deref() != Some("") { + document.add_child_to_tree(mc, &mut open_tags, child)?; + } } Event::Comment(bt) => { let child = XMLNode::comment_from_text_event(mc, bt)?; - document.add_child_to_tree(mc, &mut open_tags, child)?; + if child.node_value().as_deref() != Some("") { + document.add_child_to_tree(mc, &mut open_tags, child)?; + } } Event::Eof => break, _ => {} diff --git a/core/src/xml/tests.rs b/core/src/xml/tests.rs index ad2ccbcc1..6c5eda15c 100644 --- a/core/src/xml/tests.rs +++ b/core/src/xml/tests.rs @@ -12,23 +12,10 @@ fn parse_single_element() { let mut roots = xml.roots(); let root = roots.next().expect("Parsed document should have a root"); - assert_eq!(root.node_type(), xml::TEXT_NODE); - assert_eq!(root.node_value(), Some("".to_string())); - - let root = roots - .next() - .expect("Parsed document should have a second root"); assert_eq!(root.node_type(), xml::ELEMENT_NODE); assert_eq!(root.tag_name(), Some(XMLName::from_str("test").unwrap())); let mut root_children = root.children().unwrap(); - - let child_text = root_children - .next() - .expect("Single nodes should have an empty text child"); - assert_eq!(child_text.node_type(), xml::TEXT_NODE); - assert_eq!(child_text.node_value(), Some("".to_string())); - assert!(root_children.next().is_none()); assert!(roots.next().is_none());