Skip to content

Commit ac3ef9d

Browse files
committed
plugin/explorer: ensure env var paths are absolute
1 parent 400caa6 commit ac3ef9d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Search/EnvironmentVariables.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ internal static Dictionary<string, string> LoadEnvironmentStringPaths()
2222

2323
foreach (DictionaryEntry special in Environment.GetEnvironmentVariables())
2424
{
25-
if (Directory.Exists(special.Value.ToString()))
25+
var path = special.Value.ToString();
26+
if (Directory.Exists(path))
2627
{
28+
// we add a trailing slash to the path to make sure drive paths become valid absolute paths.
29+
// for example, if %systemdrive% is C: we turn it to C:\
30+
path = path.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
31+
// if we don't have an absolute path, we use Path.GetFullPath to get one.
32+
// for example, if %homepath% is \Users\John we turn it to C:\Users\John
33+
path = Path.IsPathFullyQualified(path) ? path : Path.GetFullPath(path);
2734
// Variables are returned with a mixture of all upper/lower case.
2835
// Call ToLower() to make the results look consistent
29-
envStringPaths.Add(special.Key.ToString().ToLower(), special.Value.ToString());
36+
envStringPaths.Add(special.Key.ToString().ToLower(), path);
3037
}
3138
}
3239

0 commit comments

Comments
 (0)