From f88b26e7ecf9b141bf72fcb8a0f66c761a821a8e 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 55196440..36f13706 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, < 3.0.0', From 0269bb3032c701583417f5d4e1c716a183225bbf 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 038fe162..7f1a4e4c 100644 --- a/binder/views.py +++ b/binder/views.py @@ -8,6 +8,7 @@ import re from collections import defaultdict, namedtuple from contextlib import ExitStack +from unicode import unicode from PIL import Image from inspect import getmro @@ -2498,7 +2499,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 395bfad8f73129adaa0039e041e0279cd4032ec9 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 7f1a4e4c..7dc4d25f 100644 --- a/binder/views.py +++ b/binder/views.py @@ -8,7 +8,7 @@ import re 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