forked from kenzuya/unshackle
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user