Merge pull request #1319 from Silvertree2010/fix/h679-docx-xlsx-xml-parser-silently-dr

Keep CDATA text in the DOCX/XLSX XML parser
This commit is contained in:
Brandon Thomas
2026-10-23 17:30:07 -04:00
committed by GitHub
+12
View File
@@ -115,6 +115,12 @@ pub(crate) fn parse(xml: &str) -> Result<El, ImportError> {
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("<a><t><![CDATA[x < y]]></t></a>").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() {