10 lines
258 B
Python
10 lines
258 B
Python
import re
|
|
|
|
|
|
def clean_filename(filename: str) -> str:
|
|
cleaned = re.sub(r"[^A-Za-z0-9._-]", "_", filename.strip())
|
|
cleaned = cleaned.strip("._-")
|
|
if not cleaned:
|
|
raise ValueError("Filename is empty after sanitization.")
|
|
return cleaned
|