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

[wasm][debugger] Revert don't need to escape special characters anymore #78320

Merged
merged 15 commits into from
Dec 8, 2022
Merged
31 changes: 29 additions & 2 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,12 @@ internal SourceFile(AssemblyInfo assembly, int id, DocumentHandle docHandle, Uri
this.doc = assembly.pdbMetadataReader.GetDocument(docHandle);
this.docHandle = docHandle;
this.url = url;
this.DebuggerFileName = url.Replace("\\", "/").Replace(":", "");
var urlWithSpecialCharCodedHex = EscapeAscii(url);
this.DebuggerFileName = urlWithSpecialCharCodedHex.Replace("\\", "/").Replace(":", "");
this.BreakableLines = new List<int>();

this.SourceUri = new Uri((Path.IsPathRooted(url) ? "file://" : "") + url, UriKind.RelativeOrAbsolute);

this.SourceUri = new Uri((Path.IsPathRooted(url) ? "file://" : "") + urlWithSpecialCharCodedHex, UriKind.RelativeOrAbsolute);
if (SourceUri.IsFile && File.Exists(SourceUri.LocalPath))
{
this.Url = this.SourceUri.ToString();
Expand All @@ -1197,6 +1199,31 @@ 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))
Expand Down
14 changes: 9 additions & 5 deletions src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -961,20 +961,23 @@ 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%23.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 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<int>(),
bp.Value["locations"][0]["columnNumber"].Value<int>(),
$"{classWithNamespace}.Evaluate");
Assert.EndsWith(expectedFileNameEscaped, ret["callFrames"][0]["url"].Value<string>(), StringComparison.InvariantCulture);
}

[Theory]
Expand Down Expand Up @@ -1097,12 +1100,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<int>(),
bp.Value["locations"][0]["columnNumber"].Value<int>(),
$"DebuggerTests.CheckChineseCharacterInPath.Evaluate");
Assert.EndsWith("debugger-test-chinese-char-in-path-ㄨ/test.cs", ret["callFrames"][0]["url"].Value<string>(), StringComparison.InvariantCulture);
}

[Fact]
Expand Down