Ignore paths with invalid chars in PathWhich
(cherry picked from commit d636ebbfe9
)
This commit is contained in:
parent
2d60a64260
commit
9fd201c7a4
@ -103,11 +103,20 @@ namespace GodotTools.Utils
|
|||||||
{
|
{
|
||||||
string[] windowsExts = Environment.GetEnvironmentVariable("PATHEXT")?.Split(PathSep) ?? Array.Empty<string>();
|
string[] windowsExts = Environment.GetEnvironmentVariable("PATHEXT")?.Split(PathSep) ?? Array.Empty<string>();
|
||||||
string[] pathDirs = Environment.GetEnvironmentVariable("PATH")?.Split(PathSep);
|
string[] pathDirs = Environment.GetEnvironmentVariable("PATH")?.Split(PathSep);
|
||||||
|
char[] invalidPathChars = Path.GetInvalidPathChars();
|
||||||
|
|
||||||
var searchDirs = new List<string>();
|
var searchDirs = new List<string>();
|
||||||
|
|
||||||
if (pathDirs != null)
|
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);
|
string nameExt = Path.GetExtension(name);
|
||||||
bool hasPathExt = !string.IsNullOrEmpty(nameExt) && windowsExts.Contains(nameExt, StringComparer.OrdinalIgnoreCase);
|
bool hasPathExt = !string.IsNullOrEmpty(nameExt) && windowsExts.Contains(nameExt, StringComparer.OrdinalIgnoreCase);
|
||||||
@ -127,11 +136,20 @@ namespace GodotTools.Utils
|
|||||||
private static string PathWhichUnix([NotNull] string name)
|
private static string PathWhichUnix([NotNull] string name)
|
||||||
{
|
{
|
||||||
string[] pathDirs = Environment.GetEnvironmentVariable("PATH")?.Split(PathSep);
|
string[] pathDirs = Environment.GetEnvironmentVariable("PATH")?.Split(PathSep);
|
||||||
|
char[] invalidPathChars = Path.GetInvalidPathChars();
|
||||||
|
|
||||||
var searchDirs = new List<string>();
|
var searchDirs = new List<string>();
|
||||||
|
|
||||||
if (pathDirs != null)
|
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
|
searchDirs.Add(System.IO.Directory.GetCurrentDirectory()); // last in the list
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user