Skip to content

Commit eddcef3

Browse files
authored
Merge pull request #1288 from Sushanth012/fix/windows-reserved-download-names
fix(webui): avoid Windows-reserved download names
2 parents 373ec46 + d01b16d commit eddcef3

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

test/services/test_webui_task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def test_completed_task_renders_subject_named_video_download(
156156
selected_nodes = []
157157
target_names = {
158158
"_DOWNLOAD_FILENAME_INVALID_PATTERN",
159+
"_WINDOWS_RESERVED_FILENAMES",
159160
"_build_video_download_name",
160161
"_normalize_task_state",
161162
"_render_generation_task_snapshot",

test/services/test_webui_task_history.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
TASK_HISTORY_CONSTANTS = {
1717
"_FINAL_VIDEO_PATTERN",
1818
"_DOWNLOAD_FILENAME_INVALID_PATTERN",
19+
"_WINDOWS_RESERVED_FILENAMES",
1920
"VOICE_MODE_TTS",
2021
"VOICE_MODE_UPLOAD",
2122
"VOICE_MODE_NONE",
@@ -90,6 +91,12 @@ def test_build_video_download_name_handles_empty_and_long_subjects():
9091
assert len(build_video_download_name("a" * 100, 1, 1)) == 84
9192

9293

94+
def test_build_video_download_name_avoids_windows_reserved_names():
95+
assert build_video_download_name("CON", 1, 1) == "_CON.mp4"
96+
assert build_video_download_name("aux.extra", 1, 1) == "_aux.extra.mp4"
97+
assert build_video_download_name("lpt1", 1, 1) == "_lpt1.mp4"
98+
99+
93100
def test_restore_requirements_block_missing_uploaded_files():
94101
params = {
95102
"video_source": "local",

webui/Main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@
138138
re.IGNORECASE,
139139
)
140140
_DOWNLOAD_FILENAME_INVALID_PATTERN = re.compile(r'[<>:"/\\|?*\x00-\x1f]')
141+
_WINDOWS_RESERVED_FILENAMES = frozenset(
142+
{"CON", "PRN", "AUX", "NUL"}
143+
| {f"COM{number}" for number in range(1, 10)}
144+
| {f"LPT{number}" for number in range(1, 10)}
145+
)
141146
_RUNTIME_CONFIG_SECTIONS = {
142147
"app": config.app,
143148
"azure": config.azure,
@@ -990,6 +995,8 @@ def _build_video_download_name(subject, index, total):
990995
safe_subject = re.sub(r"\s+", " ", safe_subject).strip(" .")[:80].rstrip(" .")
991996
if not safe_subject:
992997
safe_subject = "video"
998+
if safe_subject.split(".", 1)[0].upper() in _WINDOWS_RESERVED_FILENAMES:
999+
safe_subject = f"_{safe_subject}"
9931000

9941001
suffix = f"-{index}" if total > 1 else ""
9951002
return f"{safe_subject}{suffix}.mp4"

0 commit comments

Comments
 (0)