Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # 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
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,11 +1183,13 @@ 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(":", "");

this.DebuggerFileName = EscapeAscii(url);
this.BreakableLines = new List<int>();

this.SourceUri = new Uri((Path.IsPathRooted(url) ? "file://" : "") + url, UriKind.RelativeOrAbsolute);
if (SourceUri.IsFile && File.Exists(SourceUri.LocalPath))

this.SourceUri = new Uri((Path.IsPathRooted(url) ? "file://" : "") + DebuggerFileName, UriKind.RelativeOrAbsolute);
if (SourceUri.IsFile && File.Exists(url))
{
this.Url = this.SourceUri.ToString();
}
Expand All @@ -1197,6 +1199,21 @@ internal SourceFile(AssemblyInfo assembly, int id, DocumentHandle docHandle, Uri
}
}

private static string EscapeAscii(string path)
{
var builder = new StringBuilder();
foreach (var part in Regex.Split(path, @"([:\\/])"))
{
if (part == ":")
builder.Append(part);
else if (part == "\\" || part == "/")
builder.Append('/');
else
builder.Append(Uri.EscapeDataString(part));
}
return builder.ToString();
}

internal void AddMethod(MethodInfo mi)
{
if (!this.methods.ContainsKey(mi.Token))
Expand Down
15 changes: 10 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,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%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-%C4%85%C5%82%C3%85.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");
Console.WriteLine("olha thays - " + ret["callFrames"][0]["url"].Value<string>());
Assert.EndsWith(expectedFileNameEscaped, ret["callFrames"][0]["url"].Value<string>(), StringComparison.InvariantCulture);
}

[Theory]
Expand Down Expand Up @@ -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<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