Export csv files fixed for projects containing semicolon in their names

This commit is contained in:
clearml 2024-12-05 22:22:12 +02:00
parent 3bcbc38c4c
commit 2eee909364

View File

@ -5,6 +5,7 @@ from functools import partial
from flask import request, Response, redirect from flask import request, Response, redirect
from werkzeug.datastructures import ImmutableMultiDict from werkzeug.datastructures import ImmutableMultiDict
from werkzeug.exceptions import BadRequest from werkzeug.exceptions import BadRequest
from werkzeug.http import quote_header_value
from apiserver.apierrors import APIError from apiserver.apierrors import APIError
from apiserver.apierrors.base import BaseError from apiserver.apierrors.base import BaseError
@ -54,17 +55,18 @@ class RequestHandlers:
if call.result.filename: if call.result.filename:
# make sure that downloaded files are not cached by the client # make sure that downloaded files are not cached by the client
disable_cache = True disable_cache = True
download_name = call.result.filename
try: try:
call.result.filename.encode("ascii") download_name.encode("ascii")
except UnicodeEncodeError: except UnicodeEncodeError:
simple = unicodedata.normalize("NFKD", call.result.filename) simple = unicodedata.normalize("NFKD", download_name)
simple = simple.encode("ascii", "ignore").decode("ascii") simple = simple.encode("ascii", "ignore").decode("ascii")
# safe = RFC 5987 attr-char # safe = RFC 5987 attr-char
quoted = urllib.parse.quote(call.result.filename, safe="") quoted = urllib.parse.quote(download_name, safe="")
filenames = f"filename={simple}; filename*=UTF-8''{quoted}" filenames = f"filename={quote_header_value(simple)}; filename*=UTF-8''{quoted}"
else: else:
filenames = f"filename={call.result.filename}" filenames = f"filename={quote_header_value(download_name)}"
headers = {"Content-Disposition": "attachment; " + filenames} headers = {f"Content-Disposition": f"attachment; {filenames}"}
response = Response( response = Response(
content, content,