From 63cbaf19a75c41112ba5d8cd3f598f09c62771f4 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Wed, 4 Sep 2024 16:29:16 -0700 Subject: [PATCH] Quote the Installer Path (#1941) * Encase the installer path in quotes to protect against spaces in username being parsed poorly, and other path issues. Don't know why we didnt do this before. * fix linter --- .../src/Acquisition/WinMacGlobalInstaller.ts | 4 ++-- .../src/test/unit/WinMacGlobalInstaller.test.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/vscode-dotnet-runtime-library/src/Acquisition/WinMacGlobalInstaller.ts b/vscode-dotnet-runtime-library/src/Acquisition/WinMacGlobalInstaller.ts index 71575fb83f..1358abaea0 100644 --- a/vscode-dotnet-runtime-library/src/Acquisition/WinMacGlobalInstaller.ts +++ b/vscode-dotnet-runtime-library/src/Acquisition/WinMacGlobalInstaller.ts @@ -385,7 +385,7 @@ Please correct your PATH variable or make sure the 'open' utility is installed s } else if(workingCommand.commandRoot === 'command') { - workingCommand = CommandExecutor.makeCommand(`open`, [`-W`, `${path.resolve(installerPath)}`]); + workingCommand = CommandExecutor.makeCommand(`open`, [`-W`, `"${path.resolve(installerPath)}"`]); } this.acquisitionContext.eventStream.post(new NetInstallerBeginExecutionEvent(`The OS X .NET Installer has been launched.`)); @@ -399,7 +399,7 @@ Please correct your PATH variable or make sure the 'open' utility is installed s } else { - const command = `${path.resolve(installerPath)}`; + const command = `"${path.resolve(installerPath)}"`; let commandOptions : string[] = []; if(this.file.isElevated(this.acquisitionContext.eventStream)) { diff --git a/vscode-dotnet-runtime-library/src/test/unit/WinMacGlobalInstaller.test.ts b/vscode-dotnet-runtime-library/src/test/unit/WinMacGlobalInstaller.test.ts index 59f1a26a4c..1b9b6f6c27 100644 --- a/vscode-dotnet-runtime-library/src/test/unit/WinMacGlobalInstaller.test.ts +++ b/vscode-dotnet-runtime-library/src/test/unit/WinMacGlobalInstaller.test.ts @@ -143,12 +143,15 @@ suite('Windows & Mac Global Installer Tests', () => if(os.platform() === 'darwin') { - assert.isTrue(mockExecutor.attemptedCommand.startsWith('open'), `It ran the right mac command, open. Command found: ${mockExecutor.attemptedCommand}`) - assert.isTrue(mockExecutor.attemptedCommand.includes('-W'), 'It used the -W flag') + assert.isTrue(mockExecutor.attemptedCommand.startsWith('open'), `It ran the right mac command, open. Command found: ${mockExecutor.attemptedCommand}`); + assert.isTrue(mockExecutor.attemptedCommand.includes('-W'), 'It used the -W flag'); + assert.isTrue(mockExecutor.attemptedCommand.includes('"'), 'It put the installer in quotes for username with space in it'); } else if(os.platform() === 'win32') { - assert.isTrue(fs.existsSync(mockExecutor.attemptedCommand.split(' ')[0]), 'It ran a command to an executable that exists'); + const returnedPath = mockExecutor.attemptedCommand.split(' ')[0].slice(1, -1); + assert.isTrue(fs.existsSync(returnedPath), `It ran a command to an executable that exists: ${returnedPath}`); + assert.isTrue(mockExecutor.attemptedCommand.includes('"'), 'It put the installer in quotes for username with space in it'); if(new FileUtilities().isElevated()) { assert.include(mockExecutor.attemptedCommand, ' /quiet /install /norestart', 'It ran under the hood if it had privileges already');