Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #16842 -- Modified the RedirectView to correctly handle query s…

…trings 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
  • Loading branch information...
commit 4887a8de170ad9227d79f39f5bd3d2564f4e7ef8 1 parent 7b624c6
@jezdez jezdez authored
View
7 django/views/generic/base.py
@@ -139,12 +139,11 @@ def get_redirect_url(self, **kwargs):
are provided as kwargs to this method.
"""
if self.url:
+ url = self.url % kwargs
args = self.request.META.get('QUERY_STRING', '')
if args and self.query_string:
- url = "%s?%s" % (self.url, args)
- else:
- url = self.url
- return url % kwargs
+ url = "%s?%s" % (url, args)
+ return url
else:
return None
View
7 tests/regressiontests/generic_views/base.py
@@ -283,6 +283,13 @@ def test_include_args(self):
self.assertEqual(response.status_code, 301)
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):
"Redirection URLs can be parameterized"
response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42)
Please sign in to comment.
Something went wrong with that request. Please try again.