Luigi commited on
Commit
72c7bbc
·
1 Parent(s): 33359da

Fix filename sanitization for Chinese titles in export

Browse files

- Update _sanitize_filename() to preserve Unicode characters
- Use re.UNICODE flag to allow Chinese characters in filenames
- Clean up consecutive underscores and trim leading/trailing ones
- Fix 500 Internal Server Error when exporting with Chinese titles

src/server/services/export_service.py CHANGED
@@ -20,8 +20,12 @@ def _sanitize_filename(title: str) -> str:
20
  return ""
21
  # Remove or replace invalid filename characters
22
  sanitized = re.sub(r'[<>:"/\\|?*]', '', title)
23
- # Replace spaces and other characters with underscores
24
- sanitized = re.sub(r'[^\w\-_\.]', '_', sanitized)
 
 
 
 
25
  # Limit length
26
  return sanitized[:50] if sanitized else ""
27
 
 
20
  return ""
21
  # Remove or replace invalid filename characters
22
  sanitized = re.sub(r'[<>:"/\\|?*]', '', title)
23
+ # Replace spaces and other problematic characters with underscores, but keep Unicode letters/numbers
24
+ sanitized = re.sub(r'[^\w\-_.]', '_', sanitized, flags=re.UNICODE)
25
+ # Remove multiple consecutive underscores
26
+ sanitized = re.sub(r'_+', '_', sanitized)
27
+ # Remove leading/trailing underscores
28
+ sanitized = sanitized.strip('_')
29
  # Limit length
30
  return sanitized[:50] if sanitized else ""
31