{
return "";
}
- return string.Join(";", Arguments.Select(a => (a.Value.Contains(";") || a.Value.Contains("=")) ? $"{a.Key}=\"{a.Value}\"" : $"{a.Key}={a.Value}"));
+ return string.Join(";", Arguments.Select(a => {
+ var escapedKey = a.Key.Contains(";") || a.Key.Contains("=") ? $"\"{a.Key}\"" : a.Key;
+ var escapedValue = a.Value.Contains(";") || a.Value.Contains("=") ? $"\"{a.Value}\"" : a.Value;
+ return $"{escapedKey}={escapedValue}";
+ }));
}
}
-}
\ No newline at end of file
+}
}
[Fact]
- public void DiagnosticSourceArgumentStringTest1()
+ public void DiagnosticSourceArgumentStringTestWithEscapedValue1()
{
string diagnosticFilterString = "Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-" +
"Request.Path" +
[Fact]
- public void DiagnosticSourceArgumentStringTest2()
+ public void DiagnosticSourceArgumentStringTestWithEscapedValue2()
{
string diagnosticFilterString = "Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-" +
"Request.Path" +
Assert.Equal("DiagnosticSourceProvider:0x00000000DEADBEEF:5:FilterAndPayloadSpecs=\"Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-Request.Path;Request.Method;RequestName=SomeRequest\r\n\"",
provider.ToString());
}
+
+ [Fact]
+ public void DiagnosticSourceArgumentStringTestWithEscapedKey()
+ {
+ string diagnosticFilterString = "Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-" +
+ "Request.Path" +
+ ";Request.Method" +
+ ";RequestName=SomeRequest" +
+ "\r\n";
+
+ var provider = new EventPipeProvider("DiagnosticSourceProvider", EventLevel.Verbose, (long)(0xdeadbeef),
+ new Dictionary<string, string>()
+ {
+ { "ArgumentKeyWith;Semicolon=Equal", diagnosticFilterString }
+ });
+
+ Assert.Equal("DiagnosticSourceProvider:0x00000000DEADBEEF:5:\"ArgumentKeyWith;Semicolon=Equal\"=\"Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-Request.Path;Request.Method;RequestName=SomeRequest\r\n\"",
+ provider.ToString());
+ }
+
+ [Fact]
+ public void DiagnosticSourceArgumentStringTestWithManyArgs()
+ {
+ string diagnosticFilterString = "Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-" +
+ "Request.Path" +
+ ";Request.Method" +
+ ";RequestName=SomeRequest" +
+ "\r\n";
+
+ var provider = new EventPipeProvider("DiagnosticSourceProvider", EventLevel.Verbose, (long)(0xdeadbeef),
+ new Dictionary<string, string>()
+ {
+ { "ArgumentKeyWith;Semicolon=Equal", diagnosticFilterString },
+ { "ArgumentKeyWith;Semicolon=Equal2", diagnosticFilterString }
+ });
+
+ Assert.Equal("DiagnosticSourceProvider:0x00000000DEADBEEF:5:\"ArgumentKeyWith;Semicolon=Equal\"=\"Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-Request.Path;Request.Method;RequestName=SomeRequest\r\n\";\"ArgumentKeyWith;Semicolon=Equal2\"=\"Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-Request.Path;Request.Method;RequestName=SomeRequest\r\n\"",
+ provider.ToString());
+ }
}
}