Repository navigation
fix: replace control characters that XML 1.0 forbids when writing - #204
emschwartz wants to merge 1 commit into
Conversation
Characters such as U+001E or U+0008 in a title were written raw, which
conforming parsers reject for the whole document. They cannot be
represented even as character references, so write U+FFFD instead. A
replacement rather than a deletion keeps the neighbouring characters
from joining into new markup, e.g. `]]\u{1}>` ending a CDATA section.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68ec90c to
3d2419f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #204 +/- ##
==========================================
+ Coverage 80.98% 82.67% +1.68%
==========================================
Files 23 23
Lines 1530 1558 +28
==========================================
+ Hits 1239 1288 +49
+ Misses 291 270 -21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
You could contribute this change to |
|
Hi @andy128k, I looked into contributing it to Either way, it seems that the handling of these characters would end up being up to the user of that library, so I think it would make sense to pick a specific policy (like replacing the characters) in this crate. |
A control character in any text or attribute value (here U+001E in a title) is written raw, which makes the whole document invalid XML:
XML 1.0 forbids U+0000-U+001F other than tab, LF and CR even as
, so they can't be escaped. This wraps the output writer inChannel::write_toandpretty_write_toso each such byte is written as U+FFFD instead (a replacement rather than a deletion, so neighbouring characters can't join, e.g.]]\x01>would otherwise close a CDATA section). It covers text, CDATA, attributes and extensions in one place. U+FFFE/U+FFFF are not handled.Behavior change: round-tripping through rss's own reader now yields U+FFFD where a raw
\x01used to come back intact.Tested with
test_control_characters_replaced(title, CDATA content, enclosure URL attribute; parses the output back). Also ran the CI commands:cargo test --all-features,cargo clippy --all --all-features -- -D warnings,cargo fmt --all -- --check,cargo doc --features "validation serde".Test output before the fix
Authored by Claude (claude-sonnet-5-5, claude-opus-5-5)