Merge pull request #1064 from Silvertree2010/fix/h848-xml-text-escaping-writes-carriag

This commit is contained in:
Brandon Thomas
2026-10-23 17:09:24 -04:00
+10
View File
@@ -367,6 +367,7 @@ pub fn esc(s: &str) -> String {
'&' => o.push_str("&"),
'<' => 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>")