Merge pull request #50918 from raulsntos/fix-39432

Ignore paths with invalid chars in PathWhich
This commit is contained in:
Ignacio Roldán Etcheverry 2021-07-27 05:39:19 +02:00 committed by GitHub
commit 8ff29d1879
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,11 +113,20 @@ namespace GodotTools.Utils
{
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);
@ -137,11 +146,20 @@ namespace GodotTools.Utils
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