Sanitize individual path parts

This commit is contained in:
I-Al-Istannen 2020-11-11 09:36:20 +01:00
parent 1486a63854
commit a0ae9aee27

View File

@ -21,7 +21,8 @@ from PFERD.utils import to_path
def sanitize_path(path: PurePath) -> Optional[PurePath]:
# Escape windows illegal path characters
if os.name == 'nt':
return PurePath(re.sub(r'[<>:"/|?]', "_", str(path)))
sanitized_parts = [re.sub(r'[<>:"/|?]', "_", x) for x in list(path.parts)]
return PurePath(*sanitized_parts)
return path