Skip to content

Fix XML 1.0 invalid control characters in DecodeJsonEscapedText#949

Closed
christianhelle with Copilot wants to merge 2 commits into
mainfrom
copilot/sub-pr-948
Closed

Fix XML 1.0 invalid control characters in DecodeJsonEscapedText#949
christianhelle with Copilot wants to merge 2 commits into
mainfrom
copilot/sub-pr-948

Conversation

Copilot AI commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Description:

DecodeJsonEscapedText() was decoding \b and \f JSON escape sequences into backspace (U+0008) and form-feed (U+000C) control characters, both forbidden in XML 1.0. This could produce invalid XML documentation — causing compiler warnings or errors in projects with warnings-as-errors.

Changes:

  • \b/\f handling: Keep as literal two-character sequences instead of decoding to XML-invalid control characters.
  • StripXmlInvalidChars(): Post-filter applied to the entire decoded result, removing any characters outside the XML 1.0 valid set (#x9 | #xA | #xD | [#x20–#xD7FF] | [#xE000–#xFFFD]). Catches invalid code points from \uXXXX sequences too.
  • IsValidXml10Character(): Named helper extracted from the filter for readability.
  • Tests: Two new unit tests — one covering \b/\f literal preservation, one verifying that \uXXXX sequences producing invalid XML code points (e.g. U+0007, U+001F) are stripped.

Example OpenAPI Specifications:

swagger: '2.0'
info:
  title: Response description with control chars
  version: v0.0.1
paths:
  '/orders':
    get:
      summary: Get orders
      responses:
        "400":
          description: "Bad\brequest\u0007"

Example generated Refit interface

public partial interface IOrders
{
    /// <exception cref="ApiException">
    ///   <list type="table">
    ///     <item>
    ///       <term>400</term>
    ///       <description>Bad\brequest</description>  <!-- \b kept as literal; U+0007 stripped -->
    ///     </item>
    ///   </list>
    /// </exception>
    [Get("/orders")]
    Task<IApiResponse> GetOrders();
}

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… as literals, strip XML 1.0 invalid chars

Co-authored-by: christianhelle <710400+christianhelle@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Mar 7, 2026

Copy link
Copy Markdown

Copilot AI changed the title [WIP] Add Unicode support for XML doc comment generation Fix XML 1.0 invalid control characters in DecodeJsonEscapedText Mar 7, 2026
@christianhelle
christianhelle marked this pull request as ready for review March 7, 2026 09:31
Copilot AI review requested due to automatic review settings March 7, 2026 09:31
@codecov

codecov Bot commented Mar 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.84615% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.47%. Comparing base (608eb08) to head (0d28979).
⚠️ Report is 253 commits behind head on main.

Files with missing lines Patch % Lines
src/Refitter.Core/XmlDocumentationGenerator.cs 53.84% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #949      +/-   ##
==========================================
- Coverage   93.56%   93.47%   -0.10%     
==========================================
  Files          26       26              
  Lines        1632     1639       +7     
==========================================
+ Hits         1527     1532       +5     
+ Misses         37       36       -1     
- Partials       68       71       +3     
Flag Coverage Δ
unittests 93.47% <53.84%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Base automatically changed from unicode-support to main March 7, 2026 11:56
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.

3 participants