From d946b70f879433dc725a1781c95076fb80b9536d Mon Sep 17 00:00:00 2001 From: Parasaran Date: Sat, 19 Oct 2024 21:35:00 +0530 Subject: [PATCH] 229280: Escaping with a character based on the shell type --- .../clipboard/browser/smartPasteUtils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/terminalContrib/clipboard/browser/smartPasteUtils.ts b/src/vs/workbench/contrib/terminalContrib/clipboard/browser/smartPasteUtils.ts index 9922ab915bc5ec..6e37ebf418b97e 100644 --- a/src/vs/workbench/contrib/terminalContrib/clipboard/browser/smartPasteUtils.ts +++ b/src/vs/workbench/contrib/terminalContrib/clipboard/browser/smartPasteUtils.ts @@ -59,9 +59,9 @@ export class SmartPasteUtils { * Wraps the input path in " and escapes the " in the path * @param path input path which needs to be wrapped in " */ - static wrapAndEscapePath(path: string): string { + static wrapAndEscapePath(path: string, escapeChar: string): string { // Escape double quotes in the path - const escapedPath = path.replace(/"/g, '\\"'); + const escapedPath = path.replace(/"/g, `${escapeChar}"`); // Wrap the escaped path in double quotes return `"${escapedPath}"`; } @@ -86,16 +86,20 @@ export class SmartPasteUtils { // Escape backslashes and wrap in double quotes if necessary const escapedPath = text.replace(/\\/g, '\\\\'); if (text.includes(' ')) { - return this.wrapAndEscapePath(escapedPath); + return this.wrapAndEscapePath(escapedPath, '\\'); } return escapedPath; } case 'pwsh': + if (text.includes(' ')) { + return this.wrapAndEscapePath(text, '`'); + } + return text; case 'cmd': // Simply wrap in quotes if spaces are present if (text.includes(' ')) { - return this.wrapAndEscapePath(text); + return this.wrapAndEscapePath(text, '^'); } return text;