Skip to content

Commit

Permalink
Ignore paths with invalid chars in PathWhich
Browse files Browse the repository at this point in the history
  • Loading branch information
raulsntos committed Jul 27, 2021
1 parent e6a544c commit d636ebb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,20 @@ private static string PathWhichWindows([NotNull] string name)
{
string[] windowsExts = Environment.GetEnvironmentVariable("PATHEXT")?.Split(PathSep) ?? Array.Empty<string>();
string[] pathDirs = Environment.GetEnvironmentVariable("PATH")?.Split(PathSep);
char[] invalidPathChars = Path.GetInvalidPathChars();

var searchDirs = new List<string>();

if (pathDirs != null)
searchDirs.AddRange(pathDirs);
{
foreach (var pathDir in pathDirs)
{
if (pathDir.IndexOfAny(invalidPathChars) != -1)
continue;

searchDirs.Add(pathDir);
}
}

string nameExt = Path.GetExtension(name);
bool hasPathExt = !string.IsNullOrEmpty(nameExt) && windowsExts.Contains(nameExt, StringComparer.OrdinalIgnoreCase);
Expand All @@ -137,11 +146,20 @@ from ext in windowsExts
private static string PathWhichUnix([NotNull] string name)
{
string[] pathDirs = Environment.GetEnvironmentVariable("PATH")?.Split(PathSep);
char[] invalidPathChars = Path.GetInvalidPathChars();

var searchDirs = new List<string>();

if (pathDirs != null)
searchDirs.AddRange(pathDirs);
{
foreach (var pathDir in pathDirs)
{
if (pathDir.IndexOfAny(invalidPathChars) != -1)
continue;

searchDirs.Add(pathDir);
}
}

searchDirs.Add(System.IO.Directory.GetCurrentDirectory()); // last in the list

Expand Down

0 comments on commit d636ebb

Please sign in to comment.