Skip to content

Commit 50dc576

Browse files
committed
Improvements for mapping between script names and files
Additional characters are filtered out. Better relative path handling.
1 parent f43dd3b commit 50dc576

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

LuaDkmDebuggerComponent/LocalComponent.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Reflection;
1616
using System.Security.Cryptography;
1717
using System.Text;
18+
using System.Text.RegularExpressions;
1819
using System.Web.Script.Serialization;
1920

2021
namespace LuaDkmDebuggerComponent
@@ -1019,29 +1020,36 @@ string CheckConfigPaths(string processPath, LuaLocalProcessData processData, str
10191020
{
10201021
var finalPath = path.Replace('/', '\\');
10211022

1022-
if (!Path.IsPathRooted(finalPath))
1023+
try
10231024
{
1024-
if (processData.workingDirectory != null)
1025+
if (!Path.IsPathRooted(finalPath))
10251026
{
1026-
string test = Path.GetFullPath(Path.Combine(processData.workingDirectory, finalPath)) + winSourcePath;
1027+
if (processData.workingDirectory != null)
1028+
{
1029+
string test = Path.GetFullPath(Path.GetFullPath(Path.Combine(processData.workingDirectory, finalPath)) + winSourcePath);
10271030

1028-
if (File.Exists(test))
1029-
return test;
1030-
}
1031+
if (File.Exists(test))
1032+
return test;
1033+
}
1034+
1035+
{
1036+
string test = Path.GetFullPath(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(processPath), finalPath)) + winSourcePath);
10311037

1038+
if (File.Exists(test))
1039+
return test;
1040+
}
1041+
}
1042+
else
10321043
{
1033-
string test = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(processPath), finalPath)) + winSourcePath;
1044+
string test = Path.GetFullPath(finalPath + winSourcePath);
10341045

10351046
if (File.Exists(test))
10361047
return test;
10371048
}
10381049
}
1039-
else
1050+
catch (Exception e)
10401051
{
1041-
string test = finalPath + winSourcePath;
1042-
1043-
if (File.Exists(test))
1044-
return test;
1052+
log.Debug($"Exception while checking search path '{finalPath}': {e.Message}");
10451053
}
10461054
}
10471055
}
@@ -1105,7 +1113,9 @@ string TryFindSourcePath(string processPath, LuaLocalProcessData processData, st
11051113
// If we have source data, write it to the temp directory and return it
11061114
if (content != null && content.Length != 0)
11071115
{
1108-
string tempPath = $"{Path.GetTempPath()}{winSourcePath.Replace('\\', '+')}";
1116+
string pattern = "[<>:\"/\\\\\\|\\?\\*]";
1117+
string cleanPath = Regex.Replace(winSourcePath, pattern, "+");
1118+
string tempPath = $"{Path.GetTempPath()}{cleanPath}";
11091119

11101120
if (!tempPath.EndsWith(".lua"))
11111121
tempPath += ".lua";

0 commit comments

Comments
 (0)