Escape carriage return as 
 in XML text content

Found while testing crates/pptx/src/xml.rs:363 (esc)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-20 14:54:55 +00:00
co-authored by Claude Haiku 5.5
parent fe510bdac6
commit 18f5e17b36
+10
View File
@@ -367,6 +367,7 @@ pub fn esc(s: &str) -> String {
'&' => o.push_str("&amp;"),
'<' => o.push_str("&lt;"),
'>' => o.push_str("&gt;"),
'\r' => o.push_str("&#13;"),
c if xml_char(c) => o.push(c),
_ => {}
}
@@ -506,6 +507,15 @@ mod tests {
assert_eq!(t, vec!["one\ntwo\nthree\rfour".to_string(), "x\ny".to_string()]);
}
#[test]
fn cr_in_text_survives_write_read() {
assert_eq!(esc("a\rb"), "a&#13;b");
let mut w = W::default();
w.elt("a:t", "one\rtwo\r\nthree");
let d = parse(w.s.as_bytes()).expect("parse");
assert_eq!(d.root.text(), "one\rtwo\r\nthree");
}
#[test]
fn parse_basic_and_entities() {
let d = parse(b"<?xml version=\"1.0\"?><a:p xmlns:a=\"x\"><a:r><a:t>A &amp; B &#x41; &lt;</a:t></a:r><a:x r:id=\"rId1\" id=\"5\"/></a:p>")