Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Trying to fix again
  • Loading branch information
thaystg authored Nov 14, 2022
commit df87f8ad3c791f0c6889506bb546ead1159b8f80
28 changes: 27 additions & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,8 @@ internal SourceFile(AssemblyInfo assembly, int id, DocumentHandle docHandle, Uri
this.DebuggerFileName = url.Replace("\\", "/").Replace(":", "");
this.BreakableLines = new List<int>();

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();
Expand All @@ -1197,6 +1198,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
16 changes: 11 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,25 @@ 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<JArray>()[0];
//Assert.Equal("dotnet://debugger-test.dll/debugger-test.cs", scripts[loc["scriptId"]?.Value<string>()]);
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.True(ret["callFrames"][0]["url"].Value<string>().Contains(expectedFileNameEscaped));
}

[Theory]
Expand Down Expand Up @@ -1097,12 +1102,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.True(ret["callFrames"][0]["url"].Value<string>().Contains("debugger-test-chinese-char-in-path-ㄨ/test.cs"));
}

[Fact]
Expand Down