Skip to content

Commit

Permalink
Proper PowerShell escaping (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihil-admirari authored Jun 20, 2024
1 parent 61c62eb commit f27211b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions platform/win.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Platform-specific functions for Windows.
local mp = require('mp')
local h = require('helpers')
local utils = require('mp.utils')
local base64 = require('utils.base64')
local curl_tmpfile_path = utils.join_path(os.getenv('TEMP'), 'curl_tmp.txt')
local self = { windows = true, healthy = true, clip_util="cmd", }

Expand All @@ -20,8 +21,12 @@ self.tmp_dir = function()
end

self.copy_to_clipboard = function(text)
mp.commandv("run", "powershell", "-command",
string.format('Set-Clipboard -Value "%s"', text:gsub('"', '`"'):gsub('', '`“'):gsub('', '`”'))
mp.commandv(
"run", "powershell", "-NoLogo", "-NoProfile", "-WindowStyle", "Hidden", "-Command",
string.format(
"Set-Clipboard ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('%s')))",
base64.enc(text)
)
)
end

Expand Down

0 comments on commit f27211b

Please sign in to comment.