Interfaces: change allow list for filenames to ensure they work safely on windows. Fixes issue #1387

This commit is contained in:
eve
2024-12-09 18:30:19 +00:00
parent ba98b088cb
commit b86e839718
+3 -3
View File
@@ -59,14 +59,14 @@ class FileHandlerInterface(io.RawIOBase):
@staticmethod
def sanitize_filename(filename: str) -> str:
"""Sanititizes the filename to ensure only a specific whitelist of characters is allowed through"""
allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.- ()[]{}!$%^:#~?<>,|"
"""Sanititizes the filename to ensure only a specific allow list of characters is allowed through"""
allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.- ()[]{}!$%^#~,"
result = ""
for char in filename:
if char in allowed:
result += char
else:
result += "?"
result += "_" # change unwanted chars to an underscore
return result
def __enter__(self):