fix(core): strip trailing spaces and dots in template formatting to prevent WinError 3

- Clean up redundant spaces and separators when conditional tags (e.g. {year?}) are omitted.
- Strip leading and trailing spaces and dots in sanitize_filename and TemplateFormatter.
- Prevent FileNotFoundError [WinError 3] caused by trailing spaces in Windows directory paths.
This commit is contained in:
CodeName393
2026-07-26 18:16:36 +09:00
committed by GitHub
parent d60d8abf53
commit 41106b0d24
2 changed files with 7 additions and 2 deletions
+1
View File
@@ -142,6 +142,7 @@ def sanitize_filename(filename: str, spacer: str = ".") -> str:
filename = re.sub(r"[:; ]", spacer, filename) # structural chars to (spacer)
filename = re.sub(r"[\\*!?¿,'\"" "<>|$#~]", "", filename) # not filename safe chars
filename = re.sub(rf"[{spacer}]{{2,}}", spacer, filename) # remove extra neighbouring (spacer)s
filename = filename.strip(" .") # strip leading and trailing spaces and dots for OS path safety
return filename