Loading django/http/__init__.py +2 −2 Original line number Diff line number Diff line Loading @@ -434,14 +434,14 @@ class HttpResponseRedirect(HttpResponse): def __init__(self, redirect_to): HttpResponse.__init__(self) self['Location'] = redirect_to self['Location'] = iri_to_uri(redirect_to) class HttpResponsePermanentRedirect(HttpResponse): status_code = 301 def __init__(self, redirect_to): HttpResponse.__init__(self) self['Location'] = redirect_to self['Location'] = iri_to_uri(redirect_to) class HttpResponseNotModified(HttpResponse): status_code = 304 Loading tests/regressiontests/views/tests/specials.py +23 −3 Original line number Diff line number Diff line Loading @@ -5,11 +5,31 @@ class URLHandling(TestCase): """ Tests for URL handling in views and responses. """ def test_iri_redirect(self): redirect_target = "/views/%E4%B8%AD%E6%96%87/target/" def test_combining_redirect(self): """ Tests that redirecting to an IRI, requiring encoding before we use it in an HTTP response, is handled correctly. in an HTTP response, is handled correctly. In this case the arg to HttpRedirect is ASCII but the current request path contains non-ASCII characters so this test ensures the creation of the full path with a base non-ASCII part is handled correctly. """ response = self.client.get(u'/views/中文/') self.assertRedirects(response, "/views/%E4%B8%AD%E6%96%87/target/") self.assertRedirects(response, self.redirect_target) def test_nonascii_redirect(self): """ Tests that a non-ASCII argument to HttpRedirect is handled properly. """ response = self.client.get('/views/nonascii_redirect/') self.assertRedirects(response, self.redirect_target) def test_permanent_nonascii_redirect(self): """ Tests that a non-ASCII argument to HttpPermanentRedirect is handled properly. """ response = self.client.get('/views/permanent_nonascii_redirect/') self.assertRedirects(response, self.redirect_target, status_code=301) tests/regressiontests/views/urls.py +9 −0 Original line number Diff line number Diff line Loading @@ -97,3 +97,12 @@ urlpatterns += patterns('django.views.generic.create_update', urlpatterns += patterns('', (r'^raises/$', views.raises) ) # rediriects, both temporary and permanent, with non-ASCII targets urlpatterns += patterns('django.views.generic.simple', ('^nonascii_redirect/$', 'redirect_to', {'url': u'/views/中文/target/', 'permanent': False}), ('^permanent_nonascii_redirect/$', 'redirect_to', {'url': u'/views/中文/target/', 'permanent': True}), ) Loading
django/http/__init__.py +2 −2 Original line number Diff line number Diff line Loading @@ -434,14 +434,14 @@ class HttpResponseRedirect(HttpResponse): def __init__(self, redirect_to): HttpResponse.__init__(self) self['Location'] = redirect_to self['Location'] = iri_to_uri(redirect_to) class HttpResponsePermanentRedirect(HttpResponse): status_code = 301 def __init__(self, redirect_to): HttpResponse.__init__(self) self['Location'] = redirect_to self['Location'] = iri_to_uri(redirect_to) class HttpResponseNotModified(HttpResponse): status_code = 304 Loading
tests/regressiontests/views/tests/specials.py +23 −3 Original line number Diff line number Diff line Loading @@ -5,11 +5,31 @@ class URLHandling(TestCase): """ Tests for URL handling in views and responses. """ def test_iri_redirect(self): redirect_target = "/views/%E4%B8%AD%E6%96%87/target/" def test_combining_redirect(self): """ Tests that redirecting to an IRI, requiring encoding before we use it in an HTTP response, is handled correctly. in an HTTP response, is handled correctly. In this case the arg to HttpRedirect is ASCII but the current request path contains non-ASCII characters so this test ensures the creation of the full path with a base non-ASCII part is handled correctly. """ response = self.client.get(u'/views/中文/') self.assertRedirects(response, "/views/%E4%B8%AD%E6%96%87/target/") self.assertRedirects(response, self.redirect_target) def test_nonascii_redirect(self): """ Tests that a non-ASCII argument to HttpRedirect is handled properly. """ response = self.client.get('/views/nonascii_redirect/') self.assertRedirects(response, self.redirect_target) def test_permanent_nonascii_redirect(self): """ Tests that a non-ASCII argument to HttpPermanentRedirect is handled properly. """ response = self.client.get('/views/permanent_nonascii_redirect/') self.assertRedirects(response, self.redirect_target, status_code=301)
tests/regressiontests/views/urls.py +9 −0 Original line number Diff line number Diff line Loading @@ -97,3 +97,12 @@ urlpatterns += patterns('django.views.generic.create_update', urlpatterns += patterns('', (r'^raises/$', views.raises) ) # rediriects, both temporary and permanent, with non-ASCII targets urlpatterns += patterns('django.views.generic.simple', ('^nonascii_redirect/$', 'redirect_to', {'url': u'/views/中文/target/', 'permanent': False}), ('^permanent_nonascii_redirect/$', 'redirect_to', {'url': u'/views/中文/target/', 'permanent': True}), )