diff --git a/skills/baoyu-post-to-wechat/scripts/copy-to-clipboard.ts b/skills/baoyu-post-to-wechat/scripts/copy-to-clipboard.ts index d27e955..e990f03 100644 --- a/skills/baoyu-post-to-wechat/scripts/copy-to-clipboard.ts +++ b/skills/baoyu-post-to-wechat/scripts/copy-to-clipboard.ts @@ -228,25 +228,25 @@ async function copyHtmlLinux(htmlFilePath: string): Promise { } async function copyImageWindows(imagePath: string): Promise { + const escaped = imagePath.replace(/'/g, "''"); const ps = [ - 'param([string]$Path)', 'Add-Type -AssemblyName System.Windows.Forms', 'Add-Type -AssemblyName System.Drawing', - '$img = [System.Drawing.Image]::FromFile($Path)', + `$img = [System.Drawing.Image]::FromFile('${escaped}')`, '[System.Windows.Forms.Clipboard]::SetImage($img)', '$img.Dispose()', ].join('; '); - await runCommand('powershell.exe', ['-NoProfile', '-Sta', '-Command', ps, '-Path', imagePath]); + await runCommand('powershell.exe', ['-NoProfile', '-Sta', '-Command', ps]); } async function copyHtmlWindows(htmlFilePath: string): Promise { + const escaped = htmlFilePath.replace(/'/g, "''"); const ps = [ - 'param([string]$Path)', 'Add-Type -AssemblyName System.Windows.Forms', - '$html = Get-Content -Raw -LiteralPath $Path', + `$html = Get-Content -Raw -LiteralPath '${escaped}'`, '[System.Windows.Forms.Clipboard]::SetText($html, [System.Windows.Forms.TextDataFormat]::Html)', ].join('; '); - await runCommand('powershell.exe', ['-NoProfile', '-Sta', '-Command', ps, '-Path', htmlFilePath]); + await runCommand('powershell.exe', ['-NoProfile', '-Sta', '-Command', ps]); } async function copyImageToClipboard(imagePathInput: string): Promise {