diff --git a/Cargo.toml b/Cargo.toml index ac2b3efa3d..d28d61bcfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ validation = ["chrono", "chrono/std", "url", "mime"] with-serde = ["serde", "atom_syndication/with-serde"] [dependencies] -quick-xml = { version = "0.37", features = ["encoding"] } +quick-xml = { version = "0.37.1", features = ["encoding"] } atom_syndication = { version = "0.12", optional = true } chrono = { version = "0.4.31", optional = true, default-features = false, features = ["alloc"] } derive_builder = { version = "0.20", optional = true } diff --git a/src/toxml.rs b/src/toxml.rs index f9329dd3e2..d585091f39 100644 --- a/src/toxml.rs +++ b/src/toxml.rs @@ -86,7 +86,8 @@ impl WriterExt for Writer { { let name = name.as_ref(); self.write_event(Event::Start(BytesStart::new(name)))?; - self.write_event(Event::CData(BytesCData::new(text.as_ref())))?; + BytesCData::escaped(text.as_ref()) + .try_for_each(|event| self.write_event(Event::CData(event)))?; self.write_event(Event::End(BytesEnd::new(name)))?; Ok(()) } diff --git a/tests/write.rs b/tests/write.rs index 3b60422c2d..1d841a3ebd 100644 --- a/tests/write.rs +++ b/tests/write.rs @@ -240,6 +240,7 @@ fn test_escape() { .value("51ed8fb6-e7db-4b1d-a75a-0d1621e895b4") .build(), ) + .description("let's try & break this ]]>, shall we?".to_owned()) .content("Lorem ipsum dolor sit amet".to_owned()) .enclosure( EnclosureBuilder::default() @@ -290,6 +291,7 @@ fn test_escape() { assert!(xml.contains("http://example.com?test=1&another=true")); assert!(xml.contains("http://example.com?test=2&another=false")); assert!(xml.contains("<title>")); + assert!(xml.contains(" ]]]]>, shall we?]]>")); let channel = rss::Channel::read_from(xml.as_bytes()).unwrap(); @@ -323,6 +325,10 @@ fn test_escape() { .unwrap(), "" ); + assert_eq!( + channel.items[0].description.as_ref().unwrap(), + "let's try & break this <item> ]]>, shall we?" + ); } #[test]