Template
Fix migrate export crash on non-ASCII server names in download headers.
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user