Properly encode semicolon in argument strings for EventPipeProvider (#824)
authorSung Yoon Whang <suwhang@microsoft.com>
Wed, 12 Feb 2020 01:52:00 +0000 (17:52 -0800)
committerGitHub <noreply@github.com>
Wed, 12 Feb 2020 01:52:00 +0000 (17:52 -0800)
* Add quotation to semicolon in argument string for EventPipeProvider

* Add test

* remove dup

* Wrap the entire argument string in quotes instead

* Add more test

src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeProvider.cs
src/tests/Microsoft.Diagnostics.NETCore.Client/EventPipeProviderTests.cs

index 332ecd20a33a8c36dd13ce77b35a7dfca4425c74..e3d00f4ee614e910302be20e016d2cec8c62bc2e 100644 (file)
@@ -69,7 +69,7 @@ namespace Microsoft.Diagnostics.NETCore.Client
             {
                 return "";
             }
-            return string.Join(";", Arguments.Select(a => $"{a.Key}={a.Value}"));
+            return string.Join(";", Arguments.Select(a => (a.Value.Contains(";") || a.Value.Contains("=")) ? $"{a.Key}=\"{a.Value}\"" : $"{a.Key}={a.Value}"));
         }
 
     }
index 5f66f28e3222a7c9c350296f2172f146f80a9755..46d216d3cb7f914b3ec9112ff478e63c7a97a553 100644 (file)
@@ -109,5 +109,43 @@ namespace Microsoft.Diagnostics.NETCore.Client
             Assert.Equal("MyProvider:0x00000000DEADBEEF:5:key1=value1", provider1.ToString());
             Assert.Equal("MyProvider:0x00000000DEADBEEF:5:key1=value1;key2=value2", provider2.ToString());
         }
+
+        [Fact]
+        public void DiagnosticSourceArgumentStringTest1()
+        {
+            string diagnosticFilterString = "Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-" +
+                "Request.Path" +
+                ";Request.Method" +
+                "\r\n";
+
+            var provider = new EventPipeProvider("DiagnosticSourceProvider", EventLevel.Verbose, (long)(0xdeadbeef),
+                new Dictionary<string, string>()
+                {
+                    { "FilterAndPayloadSpecs", diagnosticFilterString }
+                });
+
+            Assert.Equal("DiagnosticSourceProvider:0x00000000DEADBEEF:5:FilterAndPayloadSpecs=\"Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-Request.Path;Request.Method\r\n\"",
+                provider.ToString());
+        }
+
+
+        [Fact]
+        public void DiagnosticSourceArgumentStringTest2()
+        {
+            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>()
+                {
+                    { "FilterAndPayloadSpecs", diagnosticFilterString }
+                });
+
+            Assert.Equal("DiagnosticSourceProvider:0x00000000DEADBEEF:5:FilterAndPayloadSpecs=\"Microsoft.AspNetCore/Microsoft.AspNetCore.Hosting.HttpRequestIn.Start@Activity1Start:-Request.Path;Request.Method;RequestName=SomeRequest\r\n\"",
+                provider.ToString());
+        }
     }
 }