astro-rss: Generate feed with proper XML escaping #5550
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Generating XML using string concatenation is dangerous and can lead to underescaping.
Just to preemptively dismiss some excuses for this unsafety 😛:
<![CDATA[…]]>
, so it was fine!” Wrong. The content might contain]]>
itself and break out of the<![CDATA[
early.&
commonly appears in URLs and needs to be escaped for XML or HTML serialization.So let’s take the
fast-xml-parser
library that we were using to validate our hand-rolled XML, and use it to properly generate XML instead.Testing
I updated the existing tests to compare the XML using
chai-xml
, so that the snapshotted XML strings didn’t need to change. This verifies that the new output is semantically equivalent.Docs
This doesn’t need any documentation changes. I even preserve support for the existing
customData
option by parsing and re-serializing the XML string.