From 56a2fdc09bbeb3bbb835c4dd79f37e2b689a4280 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 3 Feb 2021 17:42:35 +0100 Subject: [PATCH] disallow colon (:) in output template fixes #631 --- src/App.jsx | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 13da5f0e..85ba2652 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -920,29 +920,34 @@ const App = memo(() => { const generateOutSegFileNames = useCallback(({ segments = outSegments, template }) => ( segments.map(({ start, end, name = '' }, i) => { - const cutFromStr = formatDuration({ seconds: start, fileNameFriendly: true }); - const cutToStr = formatDuration({ seconds: end, fileNameFriendly: true }); - const segNum = i + 1; + const cutFromStr = formatDuration({ seconds: start, fileNameFriendly: true }); + const cutToStr = formatDuration({ seconds: end, fileNameFriendly: true }); + const segNum = i + 1; - // https://github.com/mifi/lossless-cut/issues/583 - let segSuffix = ''; - if (name) segSuffix = `-${filenamify(name)}`; - else if (segments.length > 1) segSuffix = `-seg${segNum}`; + // https://github.com/mifi/lossless-cut/issues/583 + let segSuffix = ''; + if (name) segSuffix = `-${filenamify(name)}`; + else if (segments.length > 1) segSuffix = `-seg${segNum}`; - const ext = getOutFileExtension({ isCustomFormatSelected, outFormat: fileFormat, filePath }); + const ext = getOutFileExtension({ isCustomFormatSelected, outFormat: fileFormat, filePath }); - const { name: fileNameWithoutExt } = parsePath(filePath); + const { name: fileNameWithoutExt } = parsePath(filePath); - const generated = generateSegFileName({ template, segSuffix, inputFileNameWithoutExt: fileNameWithoutExt, ext, segNum, segLabel: filenamify(name), cutFrom: cutFromStr, cutTo: cutToStr }); - return generated.substr(0, 200); // Just to be sure + const generated = generateSegFileName({ template, segSuffix, inputFileNameWithoutExt: fileNameWithoutExt, ext, segNum, segLabel: filenamify(name), cutFrom: cutFromStr, cutTo: cutToStr }); + return generated.substr(0, 200); // Just to be sure }) ), [fileFormat, filePath, isCustomFormatSelected, outSegments]); // TODO improve user feedback const isOutSegFileNamesValid = useCallback((fileNames) => fileNames.every((fileName) => { if (!filePath) return false; + + const invalidChars = [ + pathSep, + ':', // https://github.com/mifi/lossless-cut/issues/631 + ]; const sameAsInputPath = pathNormalize(pathJoin(outputDir, fileName)) === pathNormalize(filePath); - return fileName.length > 0 && !fileName.includes(pathSep) && !sameAsInputPath; + return fileName.length > 0 && !invalidChars.some((c) => fileName.includes(c)) && !sameAsInputPath; }), [outputDir, filePath]); const openSendReportDialogWithState = useCallback(async (err) => {