Fix XmlException when writing Html log with certain test names #4576
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 #3136
Bug: In the repro case, the test metadata (display name here) contains characters like

that are not valid in XML (outside of CDATA perhaps) per spec:https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char
The HtmlLogger serializes the TestResult to XML using DCS. DCS is tolerant of these invalid characters -- it will serialize as eg

and read that too. XmlTextWriter will by default serialize the same way. But in default configuration XmlReader will not read it, and throw XmlException causing the production of the Html log to fail.Fix: set XmlWriterSettings.CheckCharacters to false.
I verified that this fixes the problem locally. I tried hard to make a unit test (see first commit) but concluded that it's not mockable using public API: HtmlTransformer is internal. I guess it could be mocked using reflection or we could use an end to end test instead? I don't have more time to spend, so perhaps it's acceptable without a test.