Skip to content

[MTP Reporters Analysis] TrxReport rewrites supplementary Unicode chars as surrogate literals #8416

Closed

Description

Summary

TrxReport rewrites every supplementary Unicode character (for example emoji or other non-BMP characters) into two literal surrogate escape sequences such as \uD83D\uDE00, even though XML 1.0 allows valid [#x10000-#x10FFFF] characters.

Evidence

  • src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.Utilities.cs:117-128
    // From xml spec ... valid chars:
    // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
    // we are handling only #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
    [GeneratedRegex(@"[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD]")]
    private static partial Regex BuildInvalidXmlCharReplace();
    
    private static string RemoveInvalidXmlChar(string str) => InvalidXmlCharReplace.Replace(str, InvalidXmlEvaluator);
  • The replacement is literal text in src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.Utilities.cs:130-133
    private static string ReplaceInvalidCharacterWithUniCodeEscapeSequence(Match match)
    {
        char x = match.Value[0];
        return $@"\u{(ushort)x:x4}";
    }
  • The sanitizer is applied to report content such as stdout/stderr and exception text in src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.Results.cs:116-143.

Why this is a real issue

A test output like 😀, or a display name / exception message containing a non-BMP character, is valid XML content but will be rewritten into surrogate-literal text. That is a lossy transformation: consumers no longer see the original character, and the TRX does not round-trip the data that the test emitted.

Suggested resolution

Preserve valid surrogate pairs / supplementary characters and only escape truly invalid XML code points. In practice that means treating well-formed surrogate pairs as valid content instead of replacing each UTF-16 code unit independently.

Related issues

  • none found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/mtp-extensionsarea/trxtype/automation

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions