Skip to content

Commit 6f7e101

Browse files
authored
Merge pull request microsoft#210784 from microsoft/tyriar/210783
Properly escape values from Windows PowerShell SI
2 parents 0e28a10 + 522f27e commit 6f7e101

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,17 @@ if ($env:VSCODE_ENV_APPEND) {
5252
function Global:__VSCode-Escape-Value([string]$value) {
5353
# NOTE: In PowerShell v6.1+, this can be written `$value -replace '…', { … }` instead of `[regex]::Replace`.
5454
# Replace any non-alphanumeric characters.
55-
[regex]::Replace($value, '[\\\n;]', { param($match)
55+
$Result = [regex]::Replace($value, '[\\\n;]', { param($match)
5656
# Encode the (ascii) matches as `\x<hex>`
5757
-Join (
5858
[System.Text.Encoding]::UTF8.GetBytes($match.Value) | ForEach-Object { '\x{0:x2}' -f $_ }
5959
)
60-
}) -replace "`e", '\x1b'
60+
})
61+
# `e is only availabel in pwsh 6+
62+
if ($PSVersionTable.PSVersion.Major -lt 6) {
63+
$Result = $Result -replace "`e", '\x1b'
64+
}
65+
$Result
6166
}
6267

6368
function Global:Prompt() {

0 commit comments

Comments
 (0)