.CPL should be added to PATHEXT (#9828)

This commit is contained in:
Steve Lee
2019-08-17 22:45:13 +05:00
committed by Ilya
parent fb333fac99
commit 00949ab352
2 changed files with 34 additions and 0 deletions
@@ -35,6 +35,34 @@ namespace System.Management.Automation
/// </summary>
internal AutomationEngine(PSHost hostInterface, InitialSessionState iss)
{
#if !UNIX
// Update the env variable PathEXT to contain .CPL
var pathext = Environment.GetEnvironmentVariable("PathEXT");
pathext = pathext ?? string.Empty;
bool cplExist = false;
if (pathext != string.Empty)
{
string[] entries = pathext.Split(Utils.Separators.Semicolon);
foreach (string entry in entries)
{
string ext = entry.Trim();
if (ext.Equals(".CPL", StringComparison.OrdinalIgnoreCase))
{
cplExist = true;
break;
}
}
}
if (!cplExist)
{
pathext = (pathext == string.Empty) ? ".CPL" :
pathext.EndsWith(";", StringComparison.OrdinalIgnoreCase)
? (pathext + ".CPL") : (pathext + ";.CPL");
Environment.SetEnvironmentVariable("PathEXT", pathext);
}
#endif
Context = new ExecutionContext(this, hostInterface, iss);
EngineParser = new Language.Parser();
@@ -605,3 +605,9 @@ Describe "Verify approved aliases list" -Tags "CI" {
$result | Should -BeNullOrEmpty
}
}
Describe "PATHEXT defaults" -Tags 'CI' {
It "PATHEXT contains .CPL" -Skip:(!$IsWindows) {
$env:PATHEXT.Split(";") | Should -Contain ".CPL"
}
}