diff options
| author | NSPC911 <[email protected]> | 2026-01-07 11:41:33 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-06 21:41:33 -0600 |
| commit | dadc08ddc7f3c9b1a34e6f401a99406b6714b965 (patch) | |
| tree | 4334c402e8d89dc27c5b401934eb5d9520fc83fb | |
| parent | d7afb01d130c6702e7654d25ca622d7be32401f6 (diff) | |
| download | opencode-dadc08ddc7f3c9b1a34e6f401a99406b6714b965.tar.gz opencode-dadc08ddc7f3c9b1a34e6f401a99406b6714b965.zip | |
fix: escape backticks when passing to powershell (#7157)
| -rw-r--r-- | packages/opencode/src/cli/cmd/tui/util/clipboard.ts | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts index 398aff5af..8963867ee 100644 --- a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts +++ b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts @@ -32,7 +32,7 @@ export namespace Clipboard { if (os === "win32" || release().includes("WSL")) { const script = "Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }" - const base64 = await $`powershell.exe -command "${script}"`.nothrow().text() + const base64 = await $`powershell.exe -NonInteractive -NoProfile -command "${script}"`.nothrow().text() if (base64) { const imageBuffer = Buffer.from(base64.trim(), "base64") if (imageBuffer.length > 0) { @@ -110,8 +110,9 @@ export namespace Clipboard { if (os === "win32") { console.log("clipboard: using powershell") return async (text: string) => { - const escaped = text.replace(/"/g, '""') - await $`powershell -command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet() + // need to escape backticks because powershell uses them as escape code + const escaped = text.replace(/"/g, '""').replace(/`/g, '``') + await $`powershell -NonInteractive -NoProfile -Command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet() } } |
