From 19e4a3d4cb301e463be530a5b6a0f2bab40ea8f7 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Fri, 11 Nov 2022 09:33:09 -0300 Subject: [PATCH 1/5] Don't need to escape special characters anymore --- .../debugger/BrowserDebugProxy/DebugStore.cs | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 6d6fa4c4036caf..2a2cf46495aaa8 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -1188,8 +1188,7 @@ internal SourceFile(AssemblyInfo assembly, int id, DocumentHandle docHandle, Uri this.DebuggerFileName = url.Replace("\\", "/").Replace(":", ""); this.BreakableLines = new List(); - var urlWithSpecialCharCodedHex = EscapeAscii(url); - this.SourceUri = new Uri((Path.IsPathRooted(url) ? "file://" : "") + urlWithSpecialCharCodedHex, UriKind.RelativeOrAbsolute); + this.SourceUri = new Uri((Path.IsPathRooted(url) ? "file://" : "") + url, UriKind.RelativeOrAbsolute); if (SourceUri.IsFile && File.Exists(SourceUri.LocalPath)) { this.Url = this.SourceUri.ToString(); @@ -1200,33 +1199,6 @@ internal SourceFile(AssemblyInfo assembly, int id, DocumentHandle docHandle, Uri } } - private static string EscapeAscii(string path) - { - var builder = new StringBuilder(); - foreach (char c in path) - { - switch (c) - { - case var _ when c >= 'a' && c <= 'z': - case var _ when c >= 'A' && c <= 'Z': - case var _ when char.IsDigit(c): - case var _ when c > 255: - case var _ when c == '+' || c == ':' || c == '.' || c == '-' || c == '_' || c == '~': - builder.Append(c); - break; - case var _ when c == Path.DirectorySeparatorChar: - case var _ when c == Path.AltDirectorySeparatorChar: - case var _ when c == '\\': - builder.Append(c); - break; - default: - builder.Append(string.Format($"%{((int)c):X2}")); - break; - } - } - return builder.ToString(); - } - internal void AddMethod(MethodInfo mi) { if (!this.methods.ContainsKey(mi.Token)) From e046f3148c1af49089dd20ed707bfdbe4eb16ae9 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 14 Nov 2022 17:22:16 -0300 Subject: [PATCH 2/5] backporting 78320 --- .../debugger/BrowserDebugProxy/DebugStore.cs | 29 ++++++++++++++++++- .../debugger/DebuggerTestSuite/MiscTests.cs | 15 ++++++---- ...on-ascii-test-\304\205\305\202\303\205.cs" | 0 3 files changed, 38 insertions(+), 6 deletions(-) rename "src/mono/wasm/debugger/tests/debugger-test-special-char-in-path-#@/non-ascii-test-\304\205\305\202.cs" => "src/mono/wasm/debugger/tests/debugger-test-special-char-in-path-#@/non-ascii-test-\304\205\305\202\303\205.cs" (100%) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 2a2cf46495aaa8..8dfc9598c62ec0 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -1188,7 +1188,8 @@ internal SourceFile(AssemblyInfo assembly, int id, DocumentHandle docHandle, Uri this.DebuggerFileName = url.Replace("\\", "/").Replace(":", ""); this.BreakableLines = new List(); - this.SourceUri = new Uri((Path.IsPathRooted(url) ? "file://" : "") + url, UriKind.RelativeOrAbsolute); + var urlWithSpecialCharCodedHex = EscapeAscii(url); + this.SourceUri = new Uri((Path.IsPathRooted(url) ? "file://" : "") + urlWithSpecialCharCodedHex, UriKind.RelativeOrAbsolute); if (SourceUri.IsFile && File.Exists(SourceUri.LocalPath)) { this.Url = this.SourceUri.ToString(); @@ -1199,6 +1200,32 @@ internal SourceFile(AssemblyInfo assembly, int id, DocumentHandle docHandle, Uri } } + private static string EscapeAscii(string path) + { + var builder = new StringBuilder(); + foreach (char c in path) + { + switch (c) + { + case var _ when char.IsLetterOrDigit(c): + case var _ when c > 255: + case var _ when c == '+' || c == ':' || c == '.' || c == '-' || c == '_' || c == '~' || c == '´' || c == '`' || c == '^' || c == '¨': + builder.Append(c); + break; + case var _ when c == Path.DirectorySeparatorChar: + case var _ when c == Path.AltDirectorySeparatorChar: + case var _ when c == '\\': + builder.Append(c); + break; + default: + builder.AppendFormat("%{0:X2}", (int)c); + break; + } + } + return builder.ToString(); + } + + internal void AddMethod(MethodInfo mi) { if (!this.methods.ContainsKey(mi.Token)) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs index 137932efa99acb..1f8138d9b9974c 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs @@ -961,20 +961,24 @@ await EvaluateAndCheck( [Theory] [InlineData( "DebuggerTests.CheckSpecialCharactersInPath", - "dotnet://debugger-test-special-char-in-path.dll/test#.cs")] + "dotnet://debugger-test-special-char-in-path.dll/test#.cs", + "debugger-test-special-char-in-path-%23%40/test%23.cs")] [InlineData( "DebuggerTests.CheckSNonAsciiCharactersInPath", - "dotnet://debugger-test-special-char-in-path.dll/non-ascii-test-Ä…Å‚.cs")] + "dotnet://debugger-test-special-char-in-path.dll/non-ascii-test-Ä…Å‚.cs", + "debugger-test-special-char-in-path-%23%40/non-ascii-test-Ä…Å‚.cs")] public async Task SetBreakpointInProjectWithSpecialCharactersInPath( - string classWithNamespace, string expectedFileLocation) + string classWithNamespace, string expectedFileLocation, string expectedFileNameEscaped) { var bp = await SetBreakpointInMethod("debugger-test-special-char-in-path.dll", classWithNamespace, "Evaluate", 1); - await EvaluateAndCheck( + var loc = bp.Value["locations"]?.Value()[0]; + var ret = await EvaluateAndCheck( $"window.setTimeout(function() {{ invoke_static_method ('[debugger-test-special-char-in-path] {classWithNamespace}:Evaluate'); }}, 1);", expectedFileLocation, bp.Value["locations"][0]["lineNumber"].Value(), bp.Value["locations"][0]["columnNumber"].Value(), $"{classWithNamespace}.Evaluate"); + Assert.EndsWith(expectedFileNameEscaped, ret["callFrames"][0]["url"].Value(), StringComparison.InvariantCulture); } [Theory] @@ -1097,12 +1101,13 @@ await EvaluateAndCheck( public async Task SetBreakpointInProjectWithChineseCharactereInPath() { var bp = await SetBreakpointInMethod("debugger-test-chinese-char-in-path-ㄨ.dll", "DebuggerTests.CheckChineseCharacterInPath", "Evaluate", 1); - await EvaluateAndCheck( + var ret = await EvaluateAndCheck( $"window.setTimeout(function() {{ invoke_static_method ('[debugger-test-chinese-char-in-path-ㄨ] DebuggerTests.CheckChineseCharacterInPath:Evaluate'); }}, 1);", "dotnet://debugger-test-chinese-char-in-path-ㄨ.dll/test.cs", bp.Value["locations"][0]["lineNumber"].Value(), bp.Value["locations"][0]["columnNumber"].Value(), $"DebuggerTests.CheckChineseCharacterInPath.Evaluate"); + Assert.EndsWith("debugger-test-chinese-char-in-path-ㄨ/test.cs", ret["callFrames"][0]["url"].Value(), StringComparison.InvariantCulture); } [Fact] diff --git "a/src/mono/wasm/debugger/tests/debugger-test-special-char-in-path-#@/non-ascii-test-\304\205\305\202.cs" "b/src/mono/wasm/debugger/tests/debugger-test-special-char-in-path-#@/non-ascii-test-\304\205\305\202\303\205.cs" similarity index 100% rename from "src/mono/wasm/debugger/tests/debugger-test-special-char-in-path-#@/non-ascii-test-\304\205\305\202.cs" rename to "src/mono/wasm/debugger/tests/debugger-test-special-char-in-path-#@/non-ascii-test-\304\205\305\202\303\205.cs" From fc4723580c7254ab1605fc675b97d0ee025431d7 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 14 Nov 2022 17:25:07 -0300 Subject: [PATCH 3/5] Fix characters --- src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 8dfc9598c62ec0..bcb1b954171f6c 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -1209,7 +1209,7 @@ private static string EscapeAscii(string path) { case var _ when char.IsLetterOrDigit(c): case var _ when c > 255: - case var _ when c == '+' || c == ':' || c == '.' || c == '-' || c == '_' || c == '~' || c == '´' || c == '`' || c == '^' || c == '¨': + case var _ when c == '+' || c == ':' || c == '.' || c == '-' || c == '_' || c == '~' || c == '´' || c == '`' || c == '^' || c == '¨': builder.Append(c); break; case var _ when c == Path.DirectorySeparatorChar: From 3f91341577bb151cc51c2785955ffa10accc101a Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 14 Nov 2022 18:52:06 -0300 Subject: [PATCH 4/5] Removing unit tests. --- .../wasm/debugger/DebuggerTestSuite/MiscTests.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs index 1f8138d9b9974c..ff9e598db33223 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs @@ -961,24 +961,21 @@ await EvaluateAndCheck( [Theory] [InlineData( "DebuggerTests.CheckSpecialCharactersInPath", - "dotnet://debugger-test-special-char-in-path.dll/test#.cs", - "debugger-test-special-char-in-path-%23%40/test%23.cs")] + "dotnet://debugger-test-special-char-in-path.dll/test#.cs")] [InlineData( "DebuggerTests.CheckSNonAsciiCharactersInPath", - "dotnet://debugger-test-special-char-in-path.dll/non-ascii-test-Ä…Å‚.cs", - "debugger-test-special-char-in-path-%23%40/non-ascii-test-Ä…Å‚.cs")] + "dotnet://debugger-test-special-char-in-path.dll/non-ascii-test-ąłÅ.cs")] public async Task SetBreakpointInProjectWithSpecialCharactersInPath( - string classWithNamespace, string expectedFileLocation, string expectedFileNameEscaped) + string classWithNamespace, string expectedFileLocation) { var bp = await SetBreakpointInMethod("debugger-test-special-char-in-path.dll", classWithNamespace, "Evaluate", 1); var loc = bp.Value["locations"]?.Value()[0]; - var ret = await EvaluateAndCheck( + await EvaluateAndCheck( $"window.setTimeout(function() {{ invoke_static_method ('[debugger-test-special-char-in-path] {classWithNamespace}:Evaluate'); }}, 1);", expectedFileLocation, bp.Value["locations"][0]["lineNumber"].Value(), bp.Value["locations"][0]["columnNumber"].Value(), $"{classWithNamespace}.Evaluate"); - Assert.EndsWith(expectedFileNameEscaped, ret["callFrames"][0]["url"].Value(), StringComparison.InvariantCulture); } [Theory] @@ -1101,13 +1098,12 @@ await EvaluateAndCheck( public async Task SetBreakpointInProjectWithChineseCharactereInPath() { var bp = await SetBreakpointInMethod("debugger-test-chinese-char-in-path-ㄨ.dll", "DebuggerTests.CheckChineseCharacterInPath", "Evaluate", 1); - var ret = await EvaluateAndCheck( + await EvaluateAndCheck( $"window.setTimeout(function() {{ invoke_static_method ('[debugger-test-chinese-char-in-path-ㄨ] DebuggerTests.CheckChineseCharacterInPath:Evaluate'); }}, 1);", "dotnet://debugger-test-chinese-char-in-path-ㄨ.dll/test.cs", bp.Value["locations"][0]["lineNumber"].Value(), bp.Value["locations"][0]["columnNumber"].Value(), $"DebuggerTests.CheckChineseCharacterInPath.Evaluate"); - Assert.EndsWith("debugger-test-chinese-char-in-path-ㄨ/test.cs", ret["callFrames"][0]["url"].Value(), StringComparison.InvariantCulture); } [Fact] From 6ae64eabdd1b1ca4345b79670d4230238724686b Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 14 Nov 2022 18:52:43 -0300 Subject: [PATCH 5/5] remove unused code. --- src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs index ff9e598db33223..ee626ee4c9f6fa 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs @@ -969,7 +969,6 @@ public async Task SetBreakpointInProjectWithSpecialCharactersInPath( string classWithNamespace, string expectedFileLocation) { var bp = await SetBreakpointInMethod("debugger-test-special-char-in-path.dll", classWithNamespace, "Evaluate", 1); - var loc = bp.Value["locations"]?.Value()[0]; await EvaluateAndCheck( $"window.setTimeout(function() {{ invoke_static_method ('[debugger-test-special-char-in-path] {classWithNamespace}:Evaluate'); }}, 1);", expectedFileLocation,