Reject empty text nodes

This commit is contained in:
David Wendt 2019-12-20 23:54:26 -05:00
parent 7a9a16e598
commit 3928c7cc51
2 changed files with 6 additions and 15 deletions

View File

@ -64,12 +64,16 @@ impl<'gc> XMLDocument<'gc> {
}
Event::Text(bt) => {
let child = XMLNode::text_from_text_event(mc, bt)?;
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)?;
if child.node_value().as_deref() != Some("") {
document.add_child_to_tree(mc, &mut open_tags, child)?;
}
}
Event::Eof => break,
_ => {}
}

View File

@ -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());