From 9fd201c7a4011a20bc9964547a53300fffb2b693 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Sun, 25 Jul 2021 19:49:14 +0200 Subject: [PATCH] Ignore paths with invalid chars in PathWhich (cherry picked from commit d636ebbfe9b72f355002331f65067b5b2e165142) --- .../editor/GodotTools/GodotTools/Utils/OS.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs index 8f542822938..6e77ba8c27a 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs @@ -103,11 +103,20 @@ namespace GodotTools.Utils { string[] windowsExts = Environment.GetEnvironmentVariable("PATHEXT")?.Split(PathSep) ?? Array.Empty(); string[] pathDirs = Environment.GetEnvironmentVariable("PATH")?.Split(PathSep); + char[] invalidPathChars = Path.GetInvalidPathChars(); var searchDirs = new List(); 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); @@ -127,11 +136,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(); 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