diff --git a/src/aarecommon/utils/paths.py b/src/aarecommon/utils/paths.py new file mode 100644 index 0000000..9dea1f6 --- /dev/null +++ b/src/aarecommon/utils/paths.py @@ -0,0 +1,9 @@ +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