diff --git a/filer/admin/folderadmin.py b/filer/admin/folderadmin.py index 7aa4520e9..f636c4ff8 100644 --- a/filer/admin/folderadmin.py +++ b/filer/admin/folderadmin.py @@ -19,7 +19,7 @@ from django.shortcuts import get_object_or_404, render from django.utils.encoding import force_text from django.utils.html import escape -from django.utils.http import urlquote +from django.utils.http import urlquote, urlunquote from django.utils.safestring import mark_safe from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy, ungettext @@ -287,7 +287,7 @@ def directory_listing(self, request, folder_id=None, viewtype=None): # search q = request.GET.get('q', None) if q: - search_terms = unquote(q).split(" ") + search_terms = urlunquote(q).split(" ") search_mode = True else: search_terms = [] diff --git a/filer/tests/admin.py b/filer/tests/admin.py index 7423ff8ac..15f309ac0 100644 --- a/filer/tests/admin.py +++ b/filer/tests/admin.py @@ -887,6 +887,29 @@ class DontSearchOwnerEmailFolderAdmin(FolderAdmin): folder_qs = folderadmin.filter_folder(Folder.objects.all(), ['joe@mata.com']) self.assertEqual(len(folder_qs), 0) + def test_search_special_characters(self): + """ + Regression test for https://github.com/divio/django-filer/pull/945. + Because of a wrong unquoting function being used, searches with + some "_XX" sequences got unquoted as unicode characters. + For example, "_ec" gets unquoted as u'ì'. + """ + url = reverse('admin:filer-directory_listing', + kwargs={'folder_id': self.parent.id}) + + # Create a file with a problematic filename + problematic_file = django.core.files.base.ContentFile('some data') + filename = u'christopher_eccleston' + problematic_file.name = filename + self.spam_file = File.objects.create( + owner=self.staff_user, original_filename=filename, + file=problematic_file, folder=self.parent) + + # Valid search for the filename, should have one result + response = self.client.get(url, {'q': filename}) + item_list = response.context['paginated_items'].object_list + self.assertEqual(len(item_list), 1) + class FilerAdminContextTests(TestCase, BulkOperationsMixin): def setUp(self): diff --git a/filer/tests/migrations.py b/filer/tests/migrations.py index eff991748..af4b86383 100644 --- a/filer/tests/migrations.py +++ b/filer/tests/migrations.py @@ -6,7 +6,7 @@ import django from django.core.management import call_command from django.test import TestCase -from six import StringIO +from django.utils.six import StringIO class MigrationsTests(TestCase): diff --git a/tox.ini b/tox.ini index f67073f29..3e0ca7573 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,6 @@ ; currently broken. This functionality will be re-added (or ; re-designed later). [tox] -toxworkdir = {homedir}/.toxenvs/django-filer envlist = flake8 ; easy-thumbnails 1.x supports py27 only and has no dj17+ migrations @@ -47,8 +46,6 @@ commands = - coverage erase coverage run test_settings.py {posargs} - coverage report -passenv = - HOME setenv = custom_image: CUSTOM_IMAGE=filer.test_utils.custom_image.models.Image deps =