-
Notifications
You must be signed in to change notification settings - Fork 341
Fix XmlException when writing Html log with certain test names #4576
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a4507cb
to
46a91b8
Compare
This reverts commit d7766ee99830598a7537d9126d7d23949ed37fa4.
46a91b8
to
4a37e81
Compare
compare lines in original code: was calling public void Transform(string inputUri, string resultsFile)
{
ArgumentNullException.ThrowIfNull(inputUri);
ArgumentNullException.ThrowIfNull(resultsFile);
// SQLBUDT 276415: Prevent wiping out the content of the input file if the output file is the same
using XmlReader reader = XmlReader.Create(inputUri);
using XmlWriter writer = XmlWriter.Create(resultsFile, OutputSettings);
Transform(reader, null, writer, CreateDefaultResolver()); now calling public void Transform(XmlReader input, XmlWriter results)
{
ArgumentNullException.ThrowIfNull(input);
ArgumentNullException.ThrowIfNull(results);
Transform(input, null, results, CreateDefaultResolver());
} I believe OutputSettings above was null. |
Thanks, will have a look tomorrow. |
nohwnd
approved these changes
Jun 28, 2023
in case it's useful in future, here's the half attempt I had at a test, that I gave up on - [TestMethod]
- public void TestCompleteHandlerShouldHandleInvalidCharReferences()
- {
- VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger hl = new(_mockFileHelper.Object, new Mock<IHtmlTransformer>().Object, new DataContractSerializer(typeof(TestRunDetails)));
- hl.Initialize(_events.Object, _parameters);
-
- MemoryStream xmlStream = new();
- _mockFileHelper.Setup(x => x.GetStream(It.IsAny<string>(), FileMode.Open, FileAccess.Read)).Returns(xmlStream);
- _mockFileHelper.Setup(x => x.Exists(It.IsAny<string>())).Returns(false);
-
- MemoryStream htmlStream = new();
- _mockFileHelper.Setup(x => x.GetStream(It.IsAny<string>(), FileMode.OpenOrCreate, FileAccess.ReadWrite)).Returns(htmlStream);
- _mockFileHelper.Setup(x => x.Exists(It.IsAny<string>())).Returns(false);
-
- var testCase = new TestCase("TestName", new Uri("some://uri"), "TestSource");
- var testResult = new ObjectModel.TestResult(testCase) { Outcome = TestOutcome.Failed };
- testResult.Messages.Add(new(TestResultMessage.StandardErrorCategory, "\uFFFF"));
-
- hl.TestResultHandler(new object(), new TestResultEventArgs(testResult));
-
- hl.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, null, TimeSpan.Zero));
-
- //Assert.AreEqual(htmlFileContent, new StreamReader(htmlStream).ReadToEnd());
- } |
This was referenced Jul 22, 2025
Merged
This was referenced Sep 4, 2025
Bump Microsoft.NET.Test.Sdk from 16.9.4 to 17.13.0
Victor-GB/skills-secure-repository-supply-chain#6
Open
Open
Open
Bump Microsoft.NET.Test.Sdk from 16.9.4 to 17.13.0
Perdiga/skills-secure-repository-supply-chain-3#7
Open
Open
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.