From ac3ef9dbc76a98fd4f0b05b2a392ad9781d357e2 Mon Sep 17 00:00:00 2001 From: Ioannis G Date: Tue, 25 Aug 2020 00:20:39 +0300 Subject: [PATCH] plugin/explorer: ensure env var paths are absolute --- .../Search/EnvironmentVariables.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/EnvironmentVariables.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/EnvironmentVariables.cs index c576d6ee8..e4287a5be 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/EnvironmentVariables.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/EnvironmentVariables.cs @@ -22,11 +22,18 @@ namespace Flow.Launcher.Plugin.Explorer.Search foreach (DictionaryEntry special in Environment.GetEnvironmentVariables()) { - if (Directory.Exists(special.Value.ToString())) + var path = special.Value.ToString(); + if (Directory.Exists(path)) { + // we add a trailing slash to the path to make sure drive paths become valid absolute paths. + // for example, if %systemdrive% is C: we turn it to C:\ + path = path.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar; + // if we don't have an absolute path, we use Path.GetFullPath to get one. + // for example, if %homepath% is \Users\John we turn it to C:\Users\John + path = Path.IsPathFullyQualified(path) ? path : Path.GetFullPath(path); // Variables are returned with a mixture of all upper/lower case. // Call ToLower() to make the results look consistent - envStringPaths.Add(special.Key.ToString().ToLower(), special.Value.ToString()); + envStringPaths.Add(special.Key.ToString().ToLower(), path); } }