Reject empty text nodes
This commit is contained in:
parent
7a9a16e598
commit
3928c7cc51
|
@ -64,12 +64,16 @@ impl<'gc> XMLDocument<'gc> {
|
||||||
}
|
}
|
||||||
Event::Text(bt) => {
|
Event::Text(bt) => {
|
||||||
let child = XMLNode::text_from_text_event(mc, 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)?;
|
document.add_child_to_tree(mc, &mut open_tags, child)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Event::Comment(bt) => {
|
Event::Comment(bt) => {
|
||||||
let child = XMLNode::comment_from_text_event(mc, 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)?;
|
document.add_child_to_tree(mc, &mut open_tags, child)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Event::Eof => break,
|
Event::Eof => break,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,23 +12,10 @@ fn parse_single_element() {
|
||||||
let mut roots = xml.roots();
|
let mut roots = xml.roots();
|
||||||
|
|
||||||
let root = roots.next().expect("Parsed document should have a root");
|
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.node_type(), xml::ELEMENT_NODE);
|
||||||
assert_eq!(root.tag_name(), Some(XMLName::from_str("test").unwrap()));
|
assert_eq!(root.tag_name(), Some(XMLName::from_str("test").unwrap()));
|
||||||
|
|
||||||
let mut root_children = root.children().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!(root_children.next().is_none());
|
||||||
|
|
||||||
assert!(roots.next().is_none());
|
assert!(roots.next().is_none());
|
||||||
|
|
Loading…
Reference in New Issue