From b3c7d9141940f516942920572268e91ca8ab86bd Mon Sep 17 00:00:00 2001 From: orohi Date: Sun, 9 Aug 2026 17:45:56 +0300 Subject: [PATCH] Fix migrate export crash on non-ASCII server names in download headers. --- app.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app.py b/app.py index a002d65..de269bd 100644 --- a/app.py +++ b/app.py @@ -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: