From b6645fa44599245495ea822bdd46afda3275ddbd Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sat, 28 Sep 2024 14:33:13 +0200 Subject: [PATCH] try to escape last ffmpeg command on windows also escape quote on linux closes #2151 --- src/main/ffmpeg.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/ffmpeg.ts b/src/main/ffmpeg.ts index f05fd736..1dcc2cc5 100644 --- a/src/main/ffmpeg.ts +++ b/src/main/ffmpeg.ts @@ -24,8 +24,16 @@ export function setCustomFfPath(path: string | undefined) { customFfPath = path; } +function escapeCliArg(arg: string) { + if (isWindows) { + // https://github.com/mifi/lossless-cut/issues/2151 + return /[\s"&<>^|]/.test(arg) ? `"${arg.replaceAll('"', '""')}"` : arg; + } + return /[^\w-]/.test(arg) ? `'${arg.replaceAll("'", '\'"\'"\'')}'` : arg; +} + export function getFfCommandLine(cmd: string, args: readonly string[]) { - return `${cmd} ${args.map((arg) => (/[^\w-]/.test(arg) ? `'${arg}'` : arg)).join(' ')}`; + return `${cmd} ${args.map((arg) => escapeCliArg(arg)).join(' ')}`; } function getFfPath(cmd: string) {