spekt / xunit.testlogger

XUnit logger for vstest platform
MIT License
73 stars 15 forks source link

Should escape `TestResultInfo.Name` #25

Closed dougbu closed 3 years ago

dougbu commented 3 years ago

Test names may contain invalid XML characters and these are not currently escaped. For example https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-aspnetcore-refs-pull-26263-merge-0d498402473f4ff088/InMemory.FunctionalTests--net5.0/testResults.xml should contain the following at line 1990:

<test name="BadRequestWhenHeaderNameContainsNonASCIIOrNullCharacters(header: &quot;Head€\u0080r: value&quot;, expectedExceptionMessage: &quot;Invalid characters in header name.&quot;)" type="Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.BadHttpRequestTests" method="BadRequestWhenHeaderNameContainsNonASCIIOrNullCharacters" time="0.0647537" result="Pass">
    <traits />
</test>

Instead it contains the literal \x80 character.

The project containing these tests uses XunitXml.TestLogger v2.1.26 and runs the tests using dotnet test InMemory.FunctionalTests.dll --logger:xunit ....

I suspect the problem is where the TestResultInfois instantiated, https://github.com/spekt/xunit.testlogger/blob/3cb0b53fc0974a7cab54142c04e8de6754066967/src/Xunit.Xml.TestLogger/XunitXmlTestLogger.cs#L140-L151 and thatTestResultEventArgs.DisplayNameshould be passed throughRemoveInvalidXmlChar(...)`.