Skip to content
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

Special characters break Jsonite #5120

Closed
nohwnd opened this issue Feb 24, 2025 · 3 comments · Fixed by #5124
Closed

Special characters break Jsonite #5120

nohwnd opened this issue Feb 24, 2025 · 3 comments · Fixed by #5124
Assignees
Labels
Area: MTP Belongs to the Microsoft.Testing.Platform core library In-PR

Comments

@nohwnd
Copy link
Member

nohwnd commented Feb 24, 2025

Describe the bug

NET Framework tests will fail to run in VS when any part contains a special character.

[24/02/2025 6:18:10.960 pm] [Error] Process: C:\Users\jajares\source\repos\TestProject136\TestProject136\bin\Debug\net481\TestProject136.exe, Exception: StreamJsonRpc.RemoteInvocationException: System.ArgumentException: Invalid control character '\u0003' found in string
Parameter name: text
   at Jsonite.Json.JsonWriter.WriteString(String text) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 976
   at Jsonite.Json.JsonWriter.Write(Object value) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 835
   at Jsonite.Json.JsonWriter.WriteObject(IEnumerable`1 members) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 889
   at Jsonite.Json.JsonWriter.Write(Object value) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 844
   at Jsonite.Json.JsonWriter.WriteObject(IEnumerable`1 members) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 889
   at Jsonite.Json.JsonWriter.Write(Object value) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 844
   at Jsonite.Json.JsonWriter.WriteArray(IEnumerable list) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 918
   at Jsonite.Json.JsonWriter.Write(Object value) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 847
   at Jsonite.Json.JsonWriter.WriteObject(IEnumerable`1 members) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 889
   at Jsonite.Json.JsonWriter.Write(Object value) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 844
   at Jsonite.Json.JsonWriter.WriteObject(IEnumerable`1 members) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 889
   at Jsonite.Json.JsonWriter.Write(Object value) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 844
   at Jsonite.Json.Serialize(Object value, JsonSettings settings) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs:line 142
   at Microsoft.Testing.Platform.ServerMode.FormatterUtilities.MessageFormatter.SerializeAsync(Object obj) in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/FormatterUtilities.cs:line 26
   at Microsoft.Testing.Platform.ServerMode.StreamMessageHandler.<WriteRequestAsync>d__9.MoveNext() in /_/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/StreamMessageHandler.cs:line 127
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

Steps To Reproduce

// file MSTestSettings.cs
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
// file Test1.cs
namespace TestProject136
{
    [TestClass]
    public sealed class Test1
    {
        [TestMethod]
        public void TestMethod1()
        {
            Console.WriteLine("\u0003");
        }
    }
}
<!-- file TestProject136.csproj -->
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net8.0;net481</TargetFrameworks>
    <LangVersion>latest</LangVersion>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <EnableMSTestRunner>true</EnableMSTestRunner>
    <OutputType>Exe</OutputType>
    <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
    <!--
      Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
      For more information, visit https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-integration-dotnet-test#show-failure-per-test
      -->
    <TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
    <PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.12.6" />
    <PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.4.0" />
    <PackageReference Include="MSTest" Version="3.6.4" />
  </ItemGroup>

  <ItemGroup>
    <Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
  </ItemGroup>

</Project>

Expected behavior

Actual behavior

Additional context

This behavior is taken from the original Jsonite implementation, just converted to use our guard. See if there is any reason to not escape those chars, the \u code seems that it should work for all, we just decide to encode some in special way to keep them more readable in the json.

https://github.com/microsoft/testfx/blob/main/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Jsonite.cs#L976

@nohwnd nohwnd added this to the MSTest 3.8.3 / MTP 1.6.3 milestone Feb 24, 2025
@nohwnd nohwnd added the Area: MTP Belongs to the Microsoft.Testing.Platform core library label Feb 24, 2025
@Youssef1313
Copy link
Member

This was already reported on DC. I closed the DC feedback ticket and keeping this one.

@nohwnd nohwnd self-assigned this Feb 25, 2025
@nohwnd
Copy link
Member Author

nohwnd commented Feb 25, 2025

Also reported on internal SO: https://stackoverflow.microsoft.com/questions/445120/445926#445926

@nohwnd
Copy link
Member Author

nohwnd commented Feb 25, 2025

Fixed in main, backported in #5125.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: MTP Belongs to the Microsoft.Testing.Platform core library In-PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants