From 2538b9cc27129a93952b74ffec69476fd9307aa6 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 8 Jul 2018 21:27:29 -0600 Subject: [PATCH] Escape paths w/single quotes before passing to powershell in sq strings Fix #1404 --- src/process.ts | 9 ++++++--- src/session.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/process.ts b/src/process.ts index ccc1236b7c..ba0e64c6c9 100644 --- a/src/process.ts +++ b/src/process.ts @@ -13,6 +13,9 @@ import Settings = require("./settings"); import utils = require("./utils"); export class PowerShellProcess { + public static escapeSingleQuotes(pspath: string): string { + return pspath.replace(new RegExp("'", "g"), "''"); + } public onExited: vscode.Event; private onExitedEmitter = new vscode.EventEmitter(); @@ -52,8 +55,8 @@ export class PowerShellProcess { : ""; this.startArgs += - `-LogPath '${editorServicesLogPath}' ` + - `-SessionDetailsPath '${this.sessionFilePath}' ` + + `-LogPath '${PowerShellProcess.escapeSingleQuotes(editorServicesLogPath)}' ` + + `-SessionDetailsPath '${PowerShellProcess.escapeSingleQuotes(this.sessionFilePath)}' ` + `-FeatureFlags @(${featureFlags})`; const powerShellArgs = [ @@ -68,7 +71,7 @@ export class PowerShellProcess { powerShellArgs.push( "-Command", - "& '" + startScriptPath + "' " + this.startArgs); + "& '" + PowerShellProcess.escapeSingleQuotes(startScriptPath) + "' " + this.startArgs); let powerShellExePath = this.exePath; diff --git a/src/session.ts b/src/session.ts index 97d07c1767..a19c1b7e5e 100644 --- a/src/session.ts +++ b/src/session.ts @@ -173,7 +173,7 @@ export class SessionManager implements Middleware { `-HostProfileId 'Microsoft.VSCode' ` + `-HostVersion '${this.hostVersion}'` + `-AdditionalModules @('PowerShellEditorServices.VSCode') ` + - `-BundledModulesPath '${this.bundledModulesPath}'` + + `-BundledModulesPath '${PowerShellProcess.escapeSingleQuotes(this.bundledModulesPath)}'` + `-EnableConsoleRepl ` + `-LanguageServicePipeName LanguageService_${id}.pipe ` + `-DebugServicePipeName DebugService_${id}.pipe `;