From ba37ee9ef882deb8e917f1cae0c586a0a275e731 Mon Sep 17 00:00:00 2001 From: a8568730 Date: Thu, 8 Feb 2018 10:21:10 +0100 Subject: [PATCH] Fixed #28635 -- Fixed admin's preserved filters if the URL contains non-ASCII characters. --- .../contrib/admin/templatetags/admin_urls.py | 4 ++-- tests/admin_views/tests.py | 21 +++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/django/contrib/admin/templatetags/admin_urls.py b/django/contrib/admin/templatetags/admin_urls.py index b926fe447a..f817c254eb 100644 --- a/django/contrib/admin/templatetags/admin_urls.py +++ b/django/contrib/admin/templatetags/admin_urls.py @@ -1,4 +1,4 @@ -from urllib.parse import parse_qsl, urlparse, urlunparse +from urllib.parse import parse_qsl, unquote, urlparse, urlunparse from django import template from django.contrib.admin.utils import quote @@ -30,7 +30,7 @@ def add_preserved_filters(context, url, popup=False, to_field=None): if opts and preserved_filters: preserved_filters = dict(parse_qsl(preserved_filters)) - match_url = '/%s' % url.partition(get_script_prefix())[2] + match_url = '/%s' % unquote(url).partition(get_script_prefix())[2] try: match = resolve(match_url) except Resolver404: diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 8cdaa2c9a8..011bb2897a 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -5641,19 +5641,14 @@ class AdminKeepChangeListFiltersTests(TestCase): 'preserved_filters': self.get_preserved_filters_querystring(), 'opts': User._meta, } - - url = reverse('admin:auth_user_changelist', current_app=self.admin_site.name) - self.assertURLEqual( - self.get_changelist_url(), - add_preserved_filters(context, url), - ) - - with override_script_prefix('/prefix/'): - url = reverse('admin:auth_user_changelist', current_app=self.admin_site.name) - self.assertURLEqual( - self.get_changelist_url(), - add_preserved_filters(context, url), - ) + prefixes = ('', '/prefix/', '/後台/') + for prefix in prefixes: + with self.subTest(prefix=prefix), override_script_prefix(prefix): + url = reverse('admin:auth_user_changelist', current_app=self.admin_site.name) + self.assertURLEqual( + self.get_changelist_url(), + add_preserved_filters(context, url), + ) class NamespacedAdminKeepChangeListFiltersTests(AdminKeepChangeListFiltersTests):