From f2f111102310fa60967d53916743462e459f62ee Mon Sep 17 00:00:00 2001 From: Rob Holt Date: Wed, 30 Oct 2019 10:16:50 -0700 Subject: [PATCH 1/3] Fix crash when PowerShell selection is changed --- src/platform.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platform.ts b/src/platform.ts index 2ade340989..281be51c53 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -116,11 +116,17 @@ export class PowerShellExeFinder { * @param configuredPowerShellPath the PowerShell path configured by the user. */ public fixWindowsPowerShellPath(configuredPowerShellPath: string): string { + const altWinPS = this.findWinPS({ useAlternateBitness: true }); + + if (!altWinPS) { + return configuredPowerShellPath; + } + + const lowerAltWinPSPath = altWinPS.exePath.toLocaleLowerCase(); const lowerConfiguredPath = configuredPowerShellPath.toLocaleLowerCase(); - const lowerAltWinPSPath = this.alternateBitnessWinPS.exePath.toLocaleLowerCase(); if (lowerConfiguredPath === lowerAltWinPSPath) { - return this.winPS.exePath; + return this.findWinPS().exePath; } return configuredPowerShellPath; From b9e7f93bcad63e7d2f0d111e84942977b05e5348 Mon Sep 17 00:00:00 2001 From: Rob Holt Date: Wed, 30 Oct 2019 12:57:09 -0700 Subject: [PATCH 2/3] Change commented out dotnet global tool code --- src/platform.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform.ts b/src/platform.ts index 281be51c53..b1877501d3 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -186,7 +186,7 @@ export class PowerShellExeFinder { // Currently it cannot take startup arguments to start PSES with. // // Look for the .NET global tool - // yield this.pwshDotnetGlobalTool; + // yield this.findPSCoreDotnetGlobalTool(); // Look for PSCore preview yield this.findPSCorePreview(); From 5b281200954354df00b4681c222ebd15a80c3cce Mon Sep 17 00:00:00 2001 From: Rob Holt Date: Wed, 30 Oct 2019 14:29:59 -0700 Subject: [PATCH 3/3] Add tests --- test/platform.test.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/platform.test.ts b/test/platform.test.ts index e141795029..f6226f634e 100644 --- a/test/platform.test.ts +++ b/test/platform.test.ts @@ -594,4 +594,47 @@ suite("Platform module", () => { }); } }); + + suite("Windows PowerShell path fix", () => { + teardown(() => { + sinon.restore(); + mockFS.restore(); + }); + + for (const testPlatform of successTestCases + .filter((tp) => tp.platformDetails.operatingSystem === platform.OperatingSystem.Windows)) { + + test(`Corrects the Windows PowerShell path on ${testPlatform.name}`, () => { + setupTestEnvironment(testPlatform); + + function getWinPSPath(systemDir: string) { + return path.join( + testPlatform.environmentVars.windir, + systemDir, + "WindowsPowerShell", + "v1.0", + "powershell.exe"); + } + + const winPSPath = getWinPSPath("System32"); + + let altWinPSPath; + if (testPlatform.platformDetails.isProcess64Bit) { + altWinPSPath = getWinPSPath("SysWOW64"); + } else if (testPlatform.platformDetails.isOS64Bit) { + altWinPSPath = getWinPSPath("Sysnative"); + } else { + altWinPSPath = null; + } + + const powerShellExeFinder = new platform.PowerShellExeFinder(testPlatform.platformDetails); + + assert.strictEqual(powerShellExeFinder.fixWindowsPowerShellPath(winPSPath), winPSPath); + + if (altWinPSPath) { + assert.strictEqual(powerShellExeFinder.fixWindowsPowerShellPath(altWinPSPath), winPSPath); + } + }); + } + }); });