mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
[PTRun][Folder]Expand environment variables(#19791)
* Fix for issue 19428 Expand the environmental variables before path combine * Adding unit test
This commit is contained in:
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@@ -736,6 +736,7 @@ hmonitor
|
|||||||
HOLDENTER
|
HOLDENTER
|
||||||
HOLDESC
|
HOLDESC
|
||||||
homepage
|
homepage
|
||||||
|
HOMEPATH
|
||||||
homljgmgpmcbpjbnjpfijnhipfkiclkd
|
homljgmgpmcbpjbnjpfijnhipfkiclkd
|
||||||
HOOKPROC
|
HOOKPROC
|
||||||
Hostbackdropbrush
|
Hostbackdropbrush
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Plugin.Folder.Sources;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
namespace Microsoft.Plugin.Folder.Sources.Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class FolderHelperTests
|
||||||
|
{
|
||||||
|
[DataTestMethod]
|
||||||
|
[DataRow(@"%SYSTEMDRIVE%", true)]
|
||||||
|
[DataRow(@"%O%S", false)]
|
||||||
|
[DataRow(@"abcd", false)]
|
||||||
|
[DataRow(@"%ProgramData%", true)]
|
||||||
|
[DataRow(@"%USERPROFILE%", true)]
|
||||||
|
[DataRow(@"powertoys", false)]
|
||||||
|
|
||||||
|
// can't test %HOMEPATH% on CI, so using \User as ExpandEnvironmentVariables was moved up
|
||||||
|
[DataRow(@"\Users", true)]
|
||||||
|
[DataRow(@"Users", false)]
|
||||||
|
public void ExpandsToRootedPath(string query, bool expected)
|
||||||
|
{
|
||||||
|
var expandedQuery = FolderHelper.Expand(query);
|
||||||
|
var result = Path.IsPathRooted(expandedQuery);
|
||||||
|
Assert.AreEqual(expected, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,6 +84,8 @@ namespace Microsoft.Plugin.Folder.Sources
|
|||||||
throw new ArgumentNullException(nameof(search));
|
throw new ArgumentNullException(nameof(search));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
search = Environment.ExpandEnvironmentVariables(search);
|
||||||
|
|
||||||
var validRoots = new char[] { '\\', '/' };
|
var validRoots = new char[] { '\\', '/' };
|
||||||
|
|
||||||
if (validRoots.Contains(search[0]) && (search.Length == 1 || !validRoots.Contains(search[1])))
|
if (validRoots.Contains(search[0]) && (search.Length == 1 || !validRoots.Contains(search[1])))
|
||||||
@@ -98,7 +100,7 @@ namespace Microsoft.Plugin.Folder.Sources
|
|||||||
search = search.Length > 1 ? Path.Combine(home, search.Substring(2)) : home;
|
search = search.Length > 1 ? Path.Combine(home, search.Substring(2)) : home;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Environment.ExpandEnvironmentVariables(search);
|
return search;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user