diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlTransformer.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlTransformer.cs index 06274e9995..7fe340f3b2 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlTransformer.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlTransformer.cs @@ -20,7 +20,7 @@ internal class HtmlTransformer : IHtmlTransformer public HtmlTransformer() { _xslTransform = new XslCompiledTransform(); - _xslTransform.Load(XmlReader.Create(GetType().Assembly.GetManifestResourceStream("Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Html.xslt") ?? throw new InvalidOperationException())); + _xslTransform.Load(XmlReader.Create(GetType().Assembly.GetManifestResourceStream("Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Html.xslt") ?? throw new InvalidOperationException(), new XmlReaderSettings { CheckCharacters = false })); } /// @@ -33,7 +33,9 @@ public void Transform(string xmlFile, string htmlFile) // for example ￿. DCS will load them, but for XSL to load them here we need to pass it // a reader that we've configured to be tolerant of such references. using XmlReader xr = XmlReader.Create(xmlFile, new XmlReaderSettings() { CheckCharacters = false }); - using XmlWriter xw = XmlWriter.Create(htmlFile, new XmlWriterSettings() { CheckCharacters = false }); + + // Use output settings from the xslt, especially the output method, which is HTML, which avoids outputting broken
tags. + using XmlWriter xw = XmlWriter.Create(htmlFile, _xslTransform.OutputSettings); _xslTransform.Transform(xr, xw); } diff --git a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/LoggerTests.cs b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/LoggerTests.cs index 36378a7408..8d75310b97 100644 --- a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/LoggerTests.cs +++ b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/LoggerTests.cs @@ -69,12 +69,21 @@ public void HtmlLoggerWithFriendlyNameContainsExpectedContent(RunnerInfo runnerI InvokeVsTest(arguments); var htmlLogFilePath = Path.Combine(TempDirectory.Path, htmlFileName); - XmlDocument report = new(); - report.Load(htmlLogFilePath); + XmlDocument report = LoadReport(htmlLogFilePath); AssertExpectedHtml(report.DocumentElement!); } + private static XmlDocument LoadReport(string htmlLogFilePath) + { + // XML reader cannot handle
tags because they are not closed, and hence are not valid XML. + // They are correct HTML though, so we patch it here. + var text = File.ReadAllText(htmlLogFilePath).Replace("
", "
"); + var report = new XmlDocument(); + report.Load(new StringReader(text)); + return report; + } + [TestMethod] [NetCoreTargetFrameworkDataSource] public void TrxLoggerWithExecutorUriShouldProperlyOverwriteFile(RunnerInfo runnerInfo)