Benchmarkdotnet: Params string containing characters like quotes is not being escaped properly

Created on 3 May 2018  路  3Comments  路  Source: dotnet/BenchmarkDotNet

```C#
using BenchmarkDotNet.Attributes;
using System.Collections.Generic;

namespace Benchmarks.SystemTextJson
{
public class JsonReaderPerf
{
//[ParamsSource(nameof(ValuesForJsonString))]
[Params("{ "message": "Hello, World!" }")]
public string JsonString;

    // JsonStrings.HelloWorld => { "message": "Hello, World!" }
    // JsonStrings.HelloWorld => { \"message\": \"Hello, World!\" }
    public static IEnumerable<string> ValuesForJsonString() => new[] { JsonStrings.HelloWorld };

    [Benchmark]
    public void SomeTest() => SomeTest(JsonString);

    private static void SomeTest(string data)
    {
    }
}

}


```text
Build FAILED.

bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,39): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,46): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,50): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,55): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,55): error CS1513: } expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,62): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
    0 Warning(s)
    6 Error(s)

Example snippet from DefaultJob.not.cs (notice the un-escaped string):
```C#
// the type name must be in sync with WindowsDisassembler.BuildArguments
public class Runnable_0 : global::Benchmarks.SystemTextJson.JsonReaderPerf
{
public static void Run(IHost host)
{
Runnable_0 instance = new Runnable_0();
instance.JsonString = "{ "message": "Hello, World!" }";

        host.WriteLine();
        foreach (var infoLine in BenchmarkEnvironmentInfo.GetCurrent().ToFormattedString())
        {
            host.WriteLine("// {0}", infoLine);
        }
        var job = new Job();

```

The issue occurs if we use Params with string directly or ParamSource with string coming from a resource file (even if we escape the string explicitly).

cc @adamsitnik, @KrzysztofCwalina

bug

Most helpful comment

Verified the fix in 0.10.14.534

All 3 comments

@ahsonkhan fixed

Verified the fix in 0.10.14.534

@ahsonkhan thanks!

Was this page helpful?
0 / 5 - 0 ratings