Loading django/http/__init__.py +3 −3 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ class HttpRequest(object): current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http', self.get_host(), self.path) location = urljoin(current_uri, location) return location return iri_to_uri(location) def is_secure(self): return os.environ.get("HTTPS") == "on" Loading Loading @@ -398,14 +398,14 @@ class HttpResponseRedirect(HttpResponse): def __init__(self, redirect_to): HttpResponse.__init__(self) self['Location'] = iri_to_uri(redirect_to) self['Location'] = redirect_to class HttpResponsePermanentRedirect(HttpResponse): status_code = 301 def __init__(self, redirect_to): HttpResponse.__init__(self) self['Location'] = iri_to_uri(redirect_to) self['Location'] = redirect_to class HttpResponseNotModified(HttpResponse): status_code = 304 Loading tests/regressiontests/views/tests/__init__.py +4 −2 Original line number Diff line number Diff line from defaults import * from generic.create_update import * from generic.date_based import * from i18n import * from specials import * from static import * from generic.date_based import * from generic.create_update import * tests/regressiontests/views/tests/specials.py 0 → 100644 +15 −0 Original line number Diff line number Diff line # coding: utf-8 from django.test import TestCase class URLHandling(TestCase): """ Tests for URL handling in views and responses. """ def test_iri_redirect(self): """ Tests that redirecting to an IRI, requiring encoding before we use it in an HTTP response, is handled correctly. """ response = self.client.get(u'/views/中文/') self.assertRedirects(response, "/views/%E4%B8%AD%E6%96%87/target/") tests/regressiontests/views/urls.py +5 −0 Original line number Diff line number Diff line # coding: utf-8 from os import path from django.conf.urls.defaults import * Loading Loading @@ -38,6 +39,10 @@ urlpatterns = patterns('', # Static views (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': media_dir}), # Special URLs for particular regression cases. url(u'^中文/$', 'regressiontests.views.views.redirect'), url(u'^中文/target/$', 'regressiontests.views.views.index_page'), ) # Date-based generic views. Loading tests/regressiontests/views/views.py +8 −1 Original line number Diff line number Diff line from django.http import HttpResponse from django.http import HttpResponse, HttpResponseRedirect from django import forms from django.views.generic.create_update import create_object Loading Loading @@ -27,3 +27,10 @@ def custom_create(request): return create_object(request, post_save_redirect='/views/create_update/view/article/%(slug)s/', form_class=SlugChangingArticleForm) def redirect(request): """ Forces an HTTP redirect. """ return HttpResponseRedirect("target/") Loading
django/http/__init__.py +3 −3 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ class HttpRequest(object): current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http', self.get_host(), self.path) location = urljoin(current_uri, location) return location return iri_to_uri(location) def is_secure(self): return os.environ.get("HTTPS") == "on" Loading Loading @@ -398,14 +398,14 @@ class HttpResponseRedirect(HttpResponse): def __init__(self, redirect_to): HttpResponse.__init__(self) self['Location'] = iri_to_uri(redirect_to) self['Location'] = redirect_to class HttpResponsePermanentRedirect(HttpResponse): status_code = 301 def __init__(self, redirect_to): HttpResponse.__init__(self) self['Location'] = iri_to_uri(redirect_to) self['Location'] = redirect_to class HttpResponseNotModified(HttpResponse): status_code = 304 Loading
tests/regressiontests/views/tests/__init__.py +4 −2 Original line number Diff line number Diff line from defaults import * from generic.create_update import * from generic.date_based import * from i18n import * from specials import * from static import * from generic.date_based import * from generic.create_update import *
tests/regressiontests/views/tests/specials.py 0 → 100644 +15 −0 Original line number Diff line number Diff line # coding: utf-8 from django.test import TestCase class URLHandling(TestCase): """ Tests for URL handling in views and responses. """ def test_iri_redirect(self): """ Tests that redirecting to an IRI, requiring encoding before we use it in an HTTP response, is handled correctly. """ response = self.client.get(u'/views/中文/') self.assertRedirects(response, "/views/%E4%B8%AD%E6%96%87/target/")
tests/regressiontests/views/urls.py +5 −0 Original line number Diff line number Diff line # coding: utf-8 from os import path from django.conf.urls.defaults import * Loading Loading @@ -38,6 +39,10 @@ urlpatterns = patterns('', # Static views (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': media_dir}), # Special URLs for particular regression cases. url(u'^中文/$', 'regressiontests.views.views.redirect'), url(u'^中文/target/$', 'regressiontests.views.views.index_page'), ) # Date-based generic views. Loading
tests/regressiontests/views/views.py +8 −1 Original line number Diff line number Diff line from django.http import HttpResponse from django.http import HttpResponse, HttpResponseRedirect from django import forms from django.views.generic.create_update import create_object Loading Loading @@ -27,3 +27,10 @@ def custom_create(request): return create_object(request, post_save_redirect='/views/create_update/view/article/%(slug)s/', form_class=SlugChangingArticleForm) def redirect(request): """ Forces an HTTP redirect. """ return HttpResponseRedirect("target/")