Fix migrate export crash on non-ASCII server names in download headers.

This commit is contained in:
orohi
2026-08-09 17:45:56 +03:00
parent f9b9857460
commit b3c7d91419
+11
View File
@@ -227,6 +227,17 @@ def get_server_connect_host(server: dict, protocol: Optional[str] = None) -> str
return (server.get('host') or '').strip()
def _ascii_filename_component(value: str, *, fallback: str = 'file') -> str:
"""HTTP headers are latin-1; keep only ASCII for Content-Disposition filenames."""
text = str(value or '').strip()
# NFKD strip accents, then drop non-ASCII leftovers (e.g. Cyrillic names).
import unicodedata
text = unicodedata.normalize('NFKD', text)
text = text.encode('ascii', 'ignore').decode('ascii')
text = re.sub(r'[^A-Za-z0-9._-]+', '_', text).strip('._-')
return text or fallback
def get_current_user(request: Request, data: Optional[dict] = None):
user_id = request.session.get('user_id')
if not user_id: