Repository navigation
Escape caption subtitle paths for both ffmpeg parsers - #289
Open
codebanditssss wants to merge 1 commit into
Open
codebanditssss wants to merge 1 commit into
codebanditssss wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #287
Summary
assembly captionputs the temporary SRT path inside-vf subtitles=.... ffmpeg parses that value twice: first as a filtergraph, then as thesubtitlesfilter's option string. The current code escapes only once, so a colon or apostrophe in the temp directory reaches the option parser unescaped, and ffmpeg fails after transcription and SRT export have already finished.This change escapes the filename from the inside out:
\,'and:.\,',,,;,[and].The path is normalized with
PurePath.as_posix(). That still turns Windows\separators into/, but it no longer rewrites a literal backslash inside a POSIX directory name. Plain paths,--font-size(force_style) and the rest of the ffmpeg command are unchanged.-vfis still passed as a single argv item, so there is no shell-quoting layer.Tests
tests/test_caption_ffmpeg.pyruns the real Typercaptioncommand with real ffmpeg and a real generated video. Onlyclient.transcribeand its SRT export are faked. For each temp directory (plain,o'brien,comma,dir,semi;dir,bracket[dir],space dir, and on POSIX alsotmp:dirandback\slash), with and without--font-size 28, the test checks three things: the command exits 0, the boundary saw exactly one transcription and one SRT export, and the output's frame hashes differ from the uncaptioned input, which proves the subtitles were actually drawn.test_windows_path_filter_contractfeeds aPureWindowsPath(C:\captions\captions.srt) throughsubtitles_filterand checks that real ffmpeg parses the drive colon and renders the subtitles. On POSIX it uses a relative directory literally namedC:. This covers only the parser contract. It is not a native Windows run.tests/test_caption_exec.py: the exact-escape expectation now matches the two-level contract that the real-ffmpeg tests verify. The fakerun_ffmpegboundary undoes both levels to find the temp SRT.Before the fix, 7 of the 17 new cases fail: colon, apostrophe and literal backslash, each with and without font size, plus the drive-letter contract. The colon cases fail with
Invalid argument, the apostrophe cases withNo such file or directory. Comma, semicolon, bracket, space and plain cases already passed and stay as controls. After the fix, all of them pass.Validation
Linux (Fedora 44), Python 3.13.14, ffmpeg 8.1.2:
TERM=xterm-256colorandPYTEST_ADDOPTS=--timeout=180../scripts/check.shprintedAll checks passed.: 3791 tests passed, 99.51% branch coverage, diff-cover 100%. The mutation gate generated 0 mutants because the changed lines contain only string constants.plain,tmp:colonandtmp'quoteall exit 0 and write the captioned video.I have not tested this on native Windows. The Windows CI job will be the first native Windows run of the new real-ffmpeg tests.