Skip to content

Commit 040c216

Browse files
authored
Escape paths w/single quotes before passing to powershell in sq strings (#1411)
Fix #1404
1 parent 64dde58 commit 040c216

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/process.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import Settings = require("./settings");
1313
import utils = require("./utils");
1414

1515
export class PowerShellProcess {
16+
public static escapeSingleQuotes(pspath: string): string {
17+
return pspath.replace(new RegExp("'", "g"), "''");
18+
}
1619

1720
public onExited: vscode.Event<void>;
1821
private onExitedEmitter = new vscode.EventEmitter<void>();
@@ -52,8 +55,8 @@ export class PowerShellProcess {
5255
: "";
5356

5457
this.startArgs +=
55-
`-LogPath '${editorServicesLogPath}' ` +
56-
`-SessionDetailsPath '${this.sessionFilePath}' ` +
58+
`-LogPath '${PowerShellProcess.escapeSingleQuotes(editorServicesLogPath)}' ` +
59+
`-SessionDetailsPath '${PowerShellProcess.escapeSingleQuotes(this.sessionFilePath)}' ` +
5760
`-FeatureFlags @(${featureFlags})`;
5861

5962
const powerShellArgs = [
@@ -68,7 +71,7 @@ export class PowerShellProcess {
6871

6972
powerShellArgs.push(
7073
"-Command",
71-
"& '" + startScriptPath + "' " + this.startArgs);
74+
"& '" + PowerShellProcess.escapeSingleQuotes(startScriptPath) + "' " + this.startArgs);
7275

7376
let powerShellExePath = this.exePath;
7477

src/session.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class SessionManager implements Middleware {
173173
`-HostProfileId 'Microsoft.VSCode' ` +
174174
`-HostVersion '${this.hostVersion}'` +
175175
`-AdditionalModules @('PowerShellEditorServices.VSCode') ` +
176-
`-BundledModulesPath '${this.bundledModulesPath}'` +
176+
`-BundledModulesPath '${PowerShellProcess.escapeSingleQuotes(this.bundledModulesPath)}'` +
177177
`-EnableConsoleRepl ` +
178178
`-LanguageServicePipeName LanguageService_${id}.pipe ` +
179179
`-DebugServicePipeName DebugService_${id}.pipe `;

0 commit comments

Comments
 (0)