Fixed the csv_download function when downloading data with non-US-ASCII filenames in the "accounting.report.utils.csv_export" module.
This commit is contained in:
parent
5d87205659
commit
3a8618f7c3
@ -22,6 +22,7 @@ from abc import ABC, abstractmethod
|
||||
from datetime import timedelta, date
|
||||
from decimal import Decimal
|
||||
from io import StringIO
|
||||
from urllib.parse import quote
|
||||
|
||||
from flask import Response
|
||||
|
||||
@ -53,7 +54,7 @@ def csv_download(filename: str, rows: list[BaseCSVRow]) -> Response:
|
||||
fp.seek(0)
|
||||
response: Response = Response(fp.read(), mimetype="text/csv")
|
||||
response.headers["Content-Disposition"] \
|
||||
= f"attachment; filename={filename}"
|
||||
= f"attachment; filename={quote(filename)}"
|
||||
return response
|
||||
|
||||
|
||||
|
@ -132,6 +132,12 @@ class ReportTestCase(unittest.TestCase):
|
||||
response = client.get(f"{PREFIX}/search?q=Salary&as=csv")
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
response = client.get(f"{PREFIX}/search?q=薪水")
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
response = client.get(f"{PREFIX}/search?q=薪水&as=csv")
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_viewer(self) -> None:
|
||||
"""Test the permission as viewer.
|
||||
|
||||
@ -221,6 +227,14 @@ class ReportTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Content-Type"],
|
||||
"text/csv; charset=utf-8")
|
||||
|
||||
response = client.get(f"{PREFIX}/search?q=薪水")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = client.get(f"{PREFIX}/search?q=薪水&as=csv")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.headers["Content-Type"],
|
||||
"text/csv; charset=utf-8")
|
||||
|
||||
def test_editor(self) -> None:
|
||||
"""Test the permission as editor.
|
||||
|
||||
@ -310,6 +324,14 @@ class ReportTestCase(unittest.TestCase):
|
||||
self.assertEqual(response.headers["Content-Type"],
|
||||
"text/csv; charset=utf-8")
|
||||
|
||||
response = self.client.get(f"{PREFIX}/search?q=薪水")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.get(f"{PREFIX}/search?q=薪水&as=csv")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.headers["Content-Type"],
|
||||
"text/csv; charset=utf-8")
|
||||
|
||||
def test_empty_db(self) -> None:
|
||||
"""Tests the empty database.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user