From 4846572aa2e290840115bb07777ee6a51fa67d99 Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Sat, 16 Dec 2023 20:13:31 +0500 Subject: [PATCH] export_ratings: enforce encoding in csv export --- qllr/blueprints/export_rating/__init__.py | 2 +- tests/samples/exported_ratings_ad.csv | 2 +- tests/test_export_ratings.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/qllr/blueprints/export_rating/__init__.py b/qllr/blueprints/export_rating/__init__.py index 92ae62b..27ed047 100644 --- a/qllr/blueprints/export_rating/__init__.py +++ b/qllr/blueprints/export_rating/__init__.py @@ -44,7 +44,7 @@ async def get_document(self, request: Request, con: Connection) -> Response: resp.headers["Content-Disposition"] = ( "attachment; filename=" + request.path_params["gametype"] + "_ratings.csv" ) - resp.headers["Content-Type"] = "text/csv" + resp.headers["Content-Type"] = "text/csv; charset=UTF-8" return resp diff --git a/tests/samples/exported_ratings_ad.csv b/tests/samples/exported_ratings_ad.csv index febce17..1e7c758 100644 --- a/tests/samples/exported_ratings_ad.csv +++ b/tests/samples/exported_ratings_ad.csv @@ -45,7 +45,7 @@ Niko_;22.66286277770996;1;http://qlstats.net/player/76561198908919769 *AD*DARKY;22.406667709350586;2;http://qlstats.net/player/76561198257684581 MajinTakenaga;22.388601303100586;1;http://qlstats.net/player/76561198256969692 pandima;22.388601303100586;1;http://qlstats.net/player/76561198257864860 -Étɳ;22.264556884765625;2;http://qlstats.net/player/76561198041660726 +Étɳ;22.264556884765625;2;http://qlstats.net/player/76561198041660726 Ofelia;22.229782104492188;2;http://qlstats.net/player/76561198273108270 dobo shire;21.829530715942383;6;http://qlstats.net/player/76561198043212328 Pappy;21.537921905517578;4;http://qlstats.net/player/76561198030939512 diff --git a/tests/test_export_ratings.py b/tests/test_export_ratings.py index e6e6f13..96e55a4 100644 --- a/tests/test_export_ratings.py +++ b/tests/test_export_ratings.py @@ -21,6 +21,7 @@ def test_ratings_ad_redirect_bad_format(service): def test_ratings_ad_csv(service): resp = service.get("/export_rating/ad.csv") + assert resp.encoding == "utf-8" assert resp.text == read_sample("exported_ratings_ad.csv")