Skip to content

Fix XML escaping for release notes with special characters#758

Open
JLaPenn wants to merge 2 commits intovelopack:developfrom
JLaPenn:fix/issue-666-release-notes-xml-escaping
Open

Fix XML escaping for release notes with special characters#758
JLaPenn wants to merge 2 commits intovelopack:developfrom
JLaPenn:fix/issue-666-release-notes-xml-escaping

Conversation

@JLaPenn
Copy link

@JLaPenn JLaPenn commented Jan 6, 2026

Release notes containing XML special characters (specifically ampersands) would cause System.Xml.XmlException during package creation when the nuspec file was parsed.

The new approach opts to always wrap metadata in CDATA tags.
Initial implementation using SecurityElement.IsValidText did not catch Ampersands as it is technically valid text for XML content.

This meant that Ampersands made it to the XML parsing step that were not escaped appropriately by a CDATA wrapper.

The change here does two things.

  1. Removes the SecurityElement.IsValidText check, as it does not catch all the cases where applying a CDATA wrapper is appropriate. Instead we always wrap.
  2. Catches instances of ]]> in metadata inputs and wraps it in additional CDATA wrappers to prevent issues with unintended CDATA wrapper exits.

This fix ensures all release notes content is properly escaped before being added to the nuspec XML.

Added comprehensive unit tests that validate the escaping logic works correctly for all problematic content including XML chars, unicode, control characters, CDATA-like sequences, and very long content.

Fixes #666

James LaPenn added 2 commits January 6, 2026 13:30
Release notes containing XML special characters (specifically ampersands)
would cause System.Xml.XmlException during package creation when the
nuspec file was parsed.

This fix ensures all release notes content is properly escaped using
SecurityElement.Escape() before being added to the nuspec XML. For any
content that remains invalid after escaping, it falls back to CDATA
wrapping with proper handling of ]]> sequences.

Added comprehensive unit tests that validate the escaping logic works
correctly for all problematic content including XML chars, unicode,
control characters, CDATA-like sequences, and very long content.

Fixes velopack#666
Previous approach used SecurityElement.Escape() which converted special
characters like & to &amp;, < to &lt;, etc. This caused content to be
altered when round-tripped through the package - users would see &amp;
instead of & in their release notes.

CDATA treats all content as literal text, so no escaping is needed.
Only special case is ]]> which terminates CDATA - split it into
]]]]><![CDATA[> to preserve the sequence.

- Remove SecurityElement.Escape() from PackageBuilder.addMetadata()
- Always wrap content in CDATA
- Add unit tests verifying ]]> preservation and no double-escaping
- Fixes velopack#666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Xml.XmlException when release notes contain an ampersand

1 participant