Merge pull request #210901 from microsoft/tyriar/210783_2

Fix replacing of ESC in pwsh
This commit is contained in:
Daniel Imms 2024-04-22 03:58:05 -07:00 committed by GitHub
commit ad5ae83b39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,17 +52,12 @@ if ($env:VSCODE_ENV_APPEND) {
function Global:__VSCode-Escape-Value([string]$value) {
# NOTE: In PowerShell v6.1+, this can be written `$value -replace '…', { … }` instead of `[regex]::Replace`.
# Replace any non-alphanumeric characters.
$Result = [regex]::Replace($value, '[\\\n;]', { param($match)
[regex]::Replace($value, "[$([char]0x1b)\\\n;]", { param($match)
# Encode the (ascii) matches as `\x<hex>`
-Join (
[System.Text.Encoding]::UTF8.GetBytes($match.Value) | ForEach-Object { '\x{0:x2}' -f $_ }
)
})
# `e is only availabel in pwsh 6+
if ($PSVersionTable.PSVersion.Major -lt 6) {
$Result = $Result -replace "`e", '\x1b'
}
$Result
}
function Global:Prompt() {