cista-storage/cista/util/filename.py

14 lines
451 B
Python
Raw Normal View History

2023-10-21 20:30:47 +01:00
import unicodedata
from pathlib import PurePosixPath
from pathvalidate import sanitize_filepath
2023-10-21 20:30:47 +01:00
def sanitize(filename: str) -> str:
filename = unicodedata.normalize("NFC", filename)
# UNIX filenames can contain backslashes but for compatibility we replace them with dashes
filename = filename.replace("\\", "-")
filename = sanitize_filepath(filename)
filename = filename.strip("/")
return PurePosixPath(filename).as_posix()