Repository navigation
Preserve supplementary Unicode in TRX reports - #8451
Amaury Levé (Evangelink) merged 10 commits into
Conversation
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
| Assert.IsNull(warning); | ||
| AssertExpectedTrxFileName(fileName); | ||
| Assert.IsNotNull(memoryStream.TrxContent); | ||
| XDocument xml = memoryStream.TrxContent; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
TrxReportescaped 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
\uXXXX.Regression coverage
Example behavior: