Fix Windows path mangling for artist names with trailing dots (e.g. Fred again..)
This commit is contained in:
parent
cae2bd0c62
commit
6fa3b490ea
2 changed files with 12 additions and 0 deletions
|
|
@ -7751,6 +7751,11 @@ class DownloadsPage(QWidget):
|
||||||
sanitized = re.sub(r'[<>:"/\\|?*]', '_', filename)
|
sanitized = re.sub(r'[<>:"/\\|?*]', '_', filename)
|
||||||
# Remove multiple spaces and trim
|
# Remove multiple spaces and trim
|
||||||
sanitized = re.sub(r'\s+', ' ', sanitized).strip()
|
sanitized = re.sub(r'\s+', ' ', sanitized).strip()
|
||||||
|
# Windows forbids trailing dots/spaces on files and folders
|
||||||
|
sanitized = sanitized.rstrip('. ') or '_'
|
||||||
|
# Windows reserved device names
|
||||||
|
if re.match(r'^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|$)', sanitized, re.IGNORECASE):
|
||||||
|
sanitized = '_' + sanitized
|
||||||
# Limit length to avoid filesystem issues
|
# Limit length to avoid filesystem issues
|
||||||
return sanitized[:200] if len(sanitized) > 200 else sanitized
|
return sanitized[:200] if len(sanitized) > 200 else sanitized
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12543,6 +12543,13 @@ def _sanitize_filename(filename: str) -> str:
|
||||||
import re
|
import re
|
||||||
sanitized = re.sub(r'[<>:"/\\|?*]', '_', filename)
|
sanitized = re.sub(r'[<>:"/\\|?*]', '_', filename)
|
||||||
sanitized = re.sub(r'\s+', ' ', sanitized).strip()
|
sanitized = re.sub(r'\s+', ' ', sanitized).strip()
|
||||||
|
# Windows forbids trailing dots/spaces on files and folders.
|
||||||
|
# Artists like "Fred again.." would create mangled 8.3 short names.
|
||||||
|
sanitized = sanitized.rstrip('. ') or '_'
|
||||||
|
# Windows reserved device names (CON, PRN, AUX, NUL, COM1-9, LPT1-9)
|
||||||
|
# can't be used as file or folder names even with extensions.
|
||||||
|
if re.match(r'^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|$)', sanitized, re.IGNORECASE):
|
||||||
|
sanitized = '_' + sanitized
|
||||||
return sanitized[:200]
|
return sanitized[:200]
|
||||||
|
|
||||||
def _sanitize_context_values(context: dict) -> dict:
|
def _sanitize_context_values(context: dict) -> dict:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue