rust-syndication / rss

Library for serializing the RSS web content syndication format
https://crates.io/crates/rss
Apache License 2.0
419 stars 52 forks source link

Support CDATA or values without escaping when writing Extension.value #149

Closed nobu-k closed 1 year ago

nobu-k commented 1 year ago

The behavior of writing Extension.value to XML changed in 1.10.0. In 1.9.0 or earlier, it was written using writer.write_event(Event::Text(BytesText::from_escaped(value.as_bytes())))?;. However, after 1.10.0, it always escapes the value and there seems no way to write a value without escaping.

I'm having this issue because a service we are using requires the value of an extension to be formatted in <![CDATA[...]]>. I'm using 1.9.0 now to avoid this issue, but it'd be nice if a newer version of this library supported the old behavior as well.

andy128k commented 1 year ago

Semantically CDATA and text are the same. A compliant XML parser should work with both.

nobu-k commented 1 year ago

I totally agree with you about CDATA and they should accept the equivalent XML data, but I have no control over the service and hoped if this library could support the feature for backward compatibility.

andy128k commented 1 year ago

I'd be happy to do smth here but that generic extension API is not that flexible. You may consider to write your own extension (similar to DublinCore or iTunes) and have that logic there. There is still no clear way to embed a custom extension into the rss crate but this is something we may work on. This could be a nice feature for other users.

P.S. That will probably require to expose XML API as well.

nobu-k commented 1 year ago

Thank you for your idea. It's definitely solves my issue if i could write a custom extension, and it would be fantastic for other use cases, too.

I'm planning to apply a small patch (like adding a flag to Extension) as a workaround for my build for a while. Thanks!