Skip to content

Commit

Permalink
Replaces django's extended unquote function with urlunquote
Browse files Browse the repository at this point in the history
This avoids wrongly unescaping characters that aren't escaped by the browser, like underscores.
  • Loading branch information
Robert Kirberich committed Nov 29, 2016
1 parent 5b90ef9 commit f2c6650
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions filer/admin/folderadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down
23 changes: 23 additions & 0 deletions filer/tests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,29 @@ class DontSearchOwnerEmailFolderAdmin(FolderAdmin):
folder_qs = folderadmin.filter_folder(Folder.objects.all(), ['[email protected]'])
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):
Expand Down

0 comments on commit f2c6650

Please sign in to comment.