Skip to content

Commit

Permalink
Merge pull request #50918 from raulsntos/fix-39432
Browse files Browse the repository at this point in the history
Ignore paths with invalid chars in PathWhich
  • Loading branch information
neikeq authored Jul 27, 2021
2 parents e6a544c + d636ebb commit 8ff29d1
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 8ff29d1

Please sign in to comment.