Skip to content

Preserve supplementary Unicode in TRX reports - #8451

Merged
Amaury Levé (Evangelink) merged 10 commits into
mainfrom
copilot/mtp-reporters-analysis-fix-surrogate-literals
May 21, 2026
Merged

Amaury Levé (Evangelink) merged 10 commits into
mainfrom
copilot/mtp-reporters-analysis-fix-surrogate-literals

Conversation

Copilot AI commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

TrxReport escaped valid supplementary Unicode characters, such as emoji, as separate surrogate literals (\uD83D\uDE00). XML 1.0 allows these characters when represented as well-formed surrogate pairs, so report content lost the original text.

  • Sanitization

    • Replaced UTF-16 code-unit regex sanitization with a scanner that preserves valid surrogate pairs.
    • Continues escaping invalid XML code units, including unpaired surrogates, as \uXXXX.
  • Regression coverage

    • Added TRX tests for preserving supplementary Unicode in display names, stdout, exception messages, and stack traces.
    • Added coverage for escaping unpaired surrogate code units.

Example behavior:

"stdout 😀"        // preserved in TRX
"stdout \uD800"   // emitted as "stdout \\ud800"

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:35
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:36
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:37
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:40
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:41
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:43
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:45
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 21, 2026 08:46
Copilot AI removed the request for review from Copilot May 21, 2026 08:46
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:48
Copilot AI changed the title [WIP] Fix TrxReport surrogate literal handling for supplementary Unicode characters Preserve supplementary Unicode in TRX reports May 21, 2026
Comment thread test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxTests.cs Dismissed
Assert.IsNull(warning);
AssertExpectedTrxFileName(fileName);
Assert.IsNotNull(memoryStream.TrxContent);
XDocument xml = memoryStream.TrxContent;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keeping the existing pattern used throughout this file (e.g. lines 45-46, 66-67, 92-93, ...): Assert.IsNotNull(memoryStream.TrxContent); followed by XDocument xml = memoryStream.TrxContent;. MSTest's Assert.IsNotNull is annotated with [NotNull], so the compiler's null-state analysis flows through and there is no CS warning. Adding ! only on the two new tests would diverge from the established convention in this file.

@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review May 21, 2026 09:24
Copilot AI review requested due to automatic review settings May 21, 2026 09:24

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.

Pull request overview

This pull request updates TRX sanitization to preserve valid supplementary Unicode characters (e.g., emoji) in generated TRX XML while still escaping invalid XML UTF-16 code units (including unpaired surrogates) as \uXXXX, preventing loss of original text in report content.

Changes:

  • Replaced regex-based XML character sanitization with a UTF-16 scanner that preserves well-formed surrogate pairs.
  • Added unit tests verifying supplementary Unicode is preserved in TRX attributes/elements and that unpaired surrogates are escaped.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxTests.cs Adds regression tests for preserved supplementary Unicode and escaped unpaired surrogates in TRX output.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.Utilities.cs Reworks XML sanitization to retain valid surrogate pairs while escaping invalid UTF-16 code units.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@Evangelink
Amaury Levé (Evangelink) merged commit 006862e into main May 21, 2026
12 of 14 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the copilot/mtp-reporters-analysis-fix-surrogate-literals branch May 21, 2026 14:37
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.

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

3 participants