Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper PowerShell escaping #128

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Proper PowerShell escaping
  • Loading branch information
nihil-admirari committed Jun 20, 2024
commit c356dffbf58b33f3bc7a9a157d45220b1979e02f
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