Skip to content

Commit

Permalink
try to escape last ffmpeg command on windows
Browse files Browse the repository at this point in the history
also escape quote on linux

closes #2151
  • Loading branch information
mifi committed Sep 28, 2024
1 parent 93f47b9 commit b6645fa
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b6645fa

Please sign in to comment.