Skip to content

Commit bc38dfb

Browse files
Turbo87andy128k
authored andcommitted
Fix ]]> escaping in CDATA sections
1 parent 95a25ee commit bc38dfb

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ validation = ["chrono", "chrono/std", "url", "mime"]
2222
with-serde = ["serde", "atom_syndication/with-serde"]
2323

2424
[dependencies]
25-
quick-xml = { version = "0.37", features = ["encoding"] }
25+
quick-xml = { version = "0.37.1", features = ["encoding"] }
2626
atom_syndication = { version = "0.12", optional = true }
2727
chrono = { version = "0.4.31", optional = true, default-features = false, features = ["alloc"] }
2828
derive_builder = { version = "0.20", optional = true }

src/toxml.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ impl<W: Write> WriterExt for Writer<W> {
8686
{
8787
let name = name.as_ref();
8888
self.write_event(Event::Start(BytesStart::new(name)))?;
89-
self.write_event(Event::CData(BytesCData::new(text.as_ref())))?;
89+
BytesCData::escaped(text.as_ref())
90+
.try_for_each(|event| self.write_event(Event::CData(event)))?;
9091
self.write_event(Event::End(BytesEnd::new(name)))?;
9192
Ok(())
9293
}

tests/write.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ fn test_escape() {
240240
.value("51ed8fb6-e7db-4b1d-a75a-0d1621e895b4")
241241
.build(),
242242
)
243+
.description("let's try & break this <item> ]]>, shall we?".to_owned())
243244
.content("Lorem ipsum dolor sit amet".to_owned())
244245
.enclosure(
245246
EnclosureBuilder::default()
@@ -290,6 +291,7 @@ fn test_escape() {
290291
assert!(xml.contains("http://example.com?test=1&amp;another=true"));
291292
assert!(xml.contains("http://example.com?test=2&amp;another=false"));
292293
assert!(xml.contains("&lt;title&gt;"));
294+
assert!(xml.contains("<![CDATA[let's try & break this <item> ]]]]><![CDATA[>, shall we?]]>"));
293295

294296
let channel = rss::Channel::read_from(xml.as_bytes()).unwrap();
295297

@@ -323,6 +325,10 @@ fn test_escape() {
323325
.unwrap(),
324326
"<title>"
325327
);
328+
assert_eq!(
329+
channel.items[0].description.as_ref().unwrap(),
330+
"let's try & break this <item> ]]>, shall we?"
331+
);
326332
}
327333

328334
#[test]

0 commit comments

Comments
 (0)