mirror of
https://github.com/django/django.git
synced 2025-04-28 11:14:44 +00:00
Fixed #16842 -- Modified the RedirectView to correctly handle query strings with percent symbols. Thanks, accuser, jamey@minilop.net and Claude Paroz.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17625 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7b624c6c32
commit
4887a8de17
@ -139,12 +139,11 @@ class RedirectView(View):
|
|||||||
are provided as kwargs to this method.
|
are provided as kwargs to this method.
|
||||||
"""
|
"""
|
||||||
if self.url:
|
if self.url:
|
||||||
|
url = self.url % kwargs
|
||||||
args = self.request.META.get('QUERY_STRING', '')
|
args = self.request.META.get('QUERY_STRING', '')
|
||||||
if args and self.query_string:
|
if args and self.query_string:
|
||||||
url = "%s?%s" % (self.url, args)
|
url = "%s?%s" % (url, args)
|
||||||
else:
|
return url
|
||||||
url = self.url
|
|
||||||
return url % kwargs
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -283,6 +283,13 @@ class RedirectViewTest(unittest.TestCase):
|
|||||||
self.assertEqual(response.status_code, 301)
|
self.assertEqual(response.status_code, 301)
|
||||||
self.assertEqual(response['Location'], '/bar/?pork=spam')
|
self.assertEqual(response['Location'], '/bar/?pork=spam')
|
||||||
|
|
||||||
|
def test_include_urlencoded_args(self):
|
||||||
|
"GET arguments can be URL-encoded when included in the redirected URL"
|
||||||
|
response = RedirectView.as_view(url='/bar/', query_string=True)(
|
||||||
|
self.rf.get('/foo/?unicode=%E2%9C%93'))
|
||||||
|
self.assertEqual(response.status_code, 301)
|
||||||
|
self.assertEqual(response['Location'], '/bar/?unicode=%E2%9C%93')
|
||||||
|
|
||||||
def test_parameter_substitution(self):
|
def test_parameter_substitution(self):
|
||||||
"Redirection URLs can be parameterized"
|
"Redirection URLs can be parameterized"
|
||||||
response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42)
|
response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user