Skip to content

Conversation

@jbrinkman
Copy link
Owner

Problem

HTML reports were breaking when displaying API signatures containing generic type parameters. For example, signatures like ICollection<object> were being interpreted by browsers as HTML <object> tags instead of being displayed as intended C# code.

This caused the HTML structure to become malformed and prevented proper rendering of the reports.

Solution

  • Added HtmlEscape method: Properly encodes special HTML characters (&, <, >, ", ') to their HTML entity equivalents
  • Updated GroupChanges method: Applied HTML escaping to both old_signature and new_signature values before template rendering
  • Comprehensive test coverage: Added test case specifically for generic type HTML escaping to prevent regression

Changes

Modified Files

  • src/DotNetApiDiff/Reporting/HtmlFormatterScriban.cs
    • Added HtmlEscape static method with comprehensive character encoding
    • Updated signature handling in GroupChanges to escape HTML entities
  • tests/DotNetApiDiff.Tests/Reporting/HtmlFormatterScribanTests.cs
    • Added Format_WithGenericTypeSignatures_ProperlyEscapesHtml test method
    • Verifies proper escaping of ICollection<object> to ICollection&lt;object&gt;

Testing

The fix has been validated with:

  • ✅ Unit test specifically for generic type escaping
  • ✅ Manual verification through regenerated HTML reports
  • ✅ Browser rendering confirmation showing proper display

Impact

  • Before: Generic types like ICollection<object> broke HTML structure
  • After: Generic types display correctly as ICollection&lt;object&gt; in browsers
  • Risk: Low - only affects display formatting, no functional logic changes

This fix ensures that all API signatures with generic type parameters are properly displayed in HTML reports without breaking the document structure.

- Add HtmlEscape method to properly encode special HTML characters
- Update GroupChanges to escape old_signature and new_signature values
- Fix issue where generic types like ICollection<object> broke HTML structure
- Add comprehensive test for generic type HTML escaping
- Ensures proper display of signatures containing angle brackets

Fixes issue where generic type parameters were interpreted as HTML tags
instead of being displayed as intended in the HTML reports.
Signed-off-by: jbrinkman <[email protected]>
@jbrinkman jbrinkman merged commit 619dcd0 into main Jul 30, 2025
7 checks passed
@jbrinkman jbrinkman deleted the fix/html-escaping-generic-types branch July 30, 2025 15:45
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.

2 participants