From 2adddca276e272257f7e7c934bbf95cd9d2397fa Mon Sep 17 00:00:00 2001 From: Bob Booy Liewes Date: Tue, 17 Aug 2021 16:48:26 +0200 Subject: [PATCH 1/3] add unidecode to the requirements of django binder --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 31a0f90f..04fe562b 100755 --- a/setup.py +++ b/setup.py @@ -41,6 +41,7 @@ 'Pillow >= 3.2.0', 'django-request-id >= 1.0.0', 'requests >= 2.13.0', + 'unidecode >= 1.2.0' ], tests_require=[ 'django-hijack >= 2.1.10', From 4a9cbbedfe23c184b1271490d57169bcd940ca31 Mon Sep 17 00:00:00 2001 From: Bob Booy Liewes Date: Tue, 17 Aug 2021 16:49:38 +0200 Subject: [PATCH 2/3] unidecode filenames sent to the frontend download url, handling weird utf-8 characters --- binder/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/binder/views.py b/binder/views.py index c12c1760..a921f992 100644 --- a/binder/views.py +++ b/binder/views.py @@ -9,6 +9,7 @@ import functools from collections import defaultdict, namedtuple from contextlib import ExitStack +from unicode import unicode from PIL import Image from inspect import getmro @@ -2268,7 +2269,8 @@ def dispatch_file_field(self, request, pk=None, file_field=None): raise BinderNotFound(file_field_name) if 'download' in request.GET: - filename = self.filefield_get_name(instance=obj, request=request, file_field=file_field) + # unidecode in order to prevent weird utf-8 symbols from messing with our urls, causing issues + filename = unidecode(self.filefield_get_name(instance=obj, request=request, file_field=file_field)) if 'prefix' in request.GET: filename = request.GET['prefix'] + ' - ' + filename resp['Content-Disposition'] = 'attachment; filename="{}"'.format(filename) From 83044dae99bc8b115c9dce0afb98bf5aad9cdb72 Mon Sep 17 00:00:00 2001 From: Bob Booy Liewes Date: Tue, 17 Aug 2021 16:54:25 +0200 Subject: [PATCH 3/3] improve imports unidecode and fix linting --- binder/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binder/views.py b/binder/views.py index a921f992..1cbf7750 100644 --- a/binder/views.py +++ b/binder/views.py @@ -9,7 +9,7 @@ import functools from collections import defaultdict, namedtuple from contextlib import ExitStack -from unicode import unicode +from unidecode import unidecode from PIL import Image from inspect import getmro