mirror of https://github.com/django/django.git
Fixed #28635 -- Fixed admin's preserved filters if the URL contains non-ASCII characters.
This commit is contained in:
parent
7905815510
commit
ba37ee9ef8
|
@ -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 import template
|
||||||
from django.contrib.admin.utils import quote
|
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:
|
if opts and preserved_filters:
|
||||||
preserved_filters = dict(parse_qsl(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:
|
try:
|
||||||
match = resolve(match_url)
|
match = resolve(match_url)
|
||||||
except Resolver404:
|
except Resolver404:
|
||||||
|
|
|
@ -5641,19 +5641,14 @@ class AdminKeepChangeListFiltersTests(TestCase):
|
||||||
'preserved_filters': self.get_preserved_filters_querystring(),
|
'preserved_filters': self.get_preserved_filters_querystring(),
|
||||||
'opts': User._meta,
|
'opts': User._meta,
|
||||||
}
|
}
|
||||||
|
prefixes = ('', '/prefix/', '/後台/')
|
||||||
url = reverse('admin:auth_user_changelist', current_app=self.admin_site.name)
|
for prefix in prefixes:
|
||||||
self.assertURLEqual(
|
with self.subTest(prefix=prefix), override_script_prefix(prefix):
|
||||||
self.get_changelist_url(),
|
url = reverse('admin:auth_user_changelist', current_app=self.admin_site.name)
|
||||||
add_preserved_filters(context, url),
|
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),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class NamespacedAdminKeepChangeListFiltersTests(AdminKeepChangeListFiltersTests):
|
class NamespacedAdminKeepChangeListFiltersTests(AdminKeepChangeListFiltersTests):
|
||||||
|
|
Loading…
Reference in New Issue