Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[fix] Fix HTML logger exception on invalid XML chars in test display names #16051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
[fix] Fix HTML logger exception on invalid XML chars in test display names #16051
Changes from all commits
2b3a78382ef8e5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Performance] Regex is re-instantiated on every call via the string overload
Regex.Replace(str, invalidChar, ...)with aconst stringpattern looks up (and possibly compiles) the regex on every invocation via .NET's internal cache (size 15). This method is called 4Γ per test result; for a run with thousands of tests this accumulates.Since the project targets
netstandard2.0andnet48,[GeneratedRegex]isn't available, but astatic readonlyfield withRegexOptions.Compiledeliminates the cache lookup overhead:Minor, but worth fixing given the hot-path nature of
TestResultHandler.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed β the regex is now a
private static readonly Regex InvalidXmlCharsRegexwithRegexOptions.Compiled, eliminating the per-call lookup overhead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctness] Surrogate pairs (supplementary Unicode characters) are incorrectly stripped
The regex
[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD]has a gap between\uD7FFand\uE000that covers the entire surrogate range\uD800β\uDFFF. In .NET strings, supplementary Unicode characters (U+10000βU+10FFFF, including all emoji) are encoded as surrogate pairs β twocharvalues both in that range.DataContractSerializer/XmlWriterhandle surrogate pairs correctly and serialize them as the corresponding supplementary Unicode code point, which is valid XML 1.0 ([#x10000-#x10FFFF]). SoDataContractSerializerwill not throw on a string like"Test(π)".The current code will corrupt such strings:
"Test(π)"β"Test(\uD83D\uDE00)"β two broken escape sequences instead of the emoji. A test whose[DataRow]argument contains an emoji will have its display name silently mangled in the HTML report.Suggested fix β allow valid surrogate pairs to pass through by checking for a complete surrogate pair before replacing:
Alternatively, use
char.IsHighSurrogate/char.IsLowSurrogatein a manual loop, which is clearer and avoids nested regex complexity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed β the surrogate range
\uD800-\uDFFFis now excluded from the negated character class in the first alternative, so valid surrogate pairs pass through untouched. Two additional alternatives handle lone surrogates (unpaired high or low) using lookahead/lookbehind. Added a test that verifies "Test(π)" is preserved as-is after sanitization.Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.