diff --git a/crates/textimport/src/docx.rs b/crates/textimport/src/docx.rs index 783b010c..4d90a6b7 100644 --- a/crates/textimport/src/docx.rs +++ b/crates/textimport/src/docx.rs @@ -115,6 +115,12 @@ pub(crate) fn parse(xml: &str) -> Result { p.kids.push(Node::Text(s)); } } + Event::CData(t) => { + let s = t.decode().map(|s| s.to_string()).unwrap_or_default(); + if let Some(p) = stack.last_mut() { + p.kids.push(Node::Text(s)); + } + } Event::GeneralRef(e) => { let name = String::from_utf8_lossy(&e).to_string(); let s = match name.as_str() { @@ -578,6 +584,12 @@ mod tests { use super::*; use std::io::Write; + #[test] + fn cdata_text() { + let el = parse("").unwrap(); + assert_eq!(el.child("t").unwrap().text(), "x < y"); + } + /// Issue #712: nesting past the budget is an error from the parser, not a stack overflow later. #[test] fn nesting_past_the_budget_is_refused() {