Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #10267 -- Correctly handle IRIs in HttpResponse.build_a…

…bsolute_uri().

Backport of r10539 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10540 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6771f4e348926608a86bc5152defd90a82fa3624 1 parent 18baad0
Malcolm Tredinnick authored April 12, 2009
6  django/http/__init__.py
@@ -72,7 +72,7 @@ def build_absolute_uri(self, location=None):
72 72
             current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http',
73 73
                                          self.get_host(), self.path)
74 74
             location = urljoin(current_uri, location)
75  
-        return location
  75
+        return iri_to_uri(location)
76 76
 
77 77
     def is_secure(self):
78 78
         return os.environ.get("HTTPS") == "on"
@@ -398,14 +398,14 @@ class HttpResponseRedirect(HttpResponse):
398 398
 
399 399
     def __init__(self, redirect_to):
400 400
         HttpResponse.__init__(self)
401  
-        self['Location'] = iri_to_uri(redirect_to)
  401
+        self['Location'] = redirect_to
402 402
 
403 403
 class HttpResponsePermanentRedirect(HttpResponse):
404 404
     status_code = 301
405 405
 
406 406
     def __init__(self, redirect_to):
407 407
         HttpResponse.__init__(self)
408  
-        self['Location'] = iri_to_uri(redirect_to)
  408
+        self['Location'] = redirect_to
409 409
 
410 410
 class HttpResponseNotModified(HttpResponse):
411 411
     status_code = 304
6  tests/regressiontests/views/tests/__init__.py
... ...
@@ -1,5 +1,7 @@
1 1
 from defaults import *
  2
+from generic.create_update import *
  3
+from generic.date_based import *
2 4
 from i18n import *
  5
+from specials import *
3 6
 from static import *
4  
-from generic.date_based import *
5  
-from generic.create_update import *
  7
+
15  tests/regressiontests/views/tests/specials.py
... ...
@@ -0,0 +1,15 @@
  1
+# coding: utf-8
  2
+from django.test import TestCase
  3
+
  4
+class URLHandling(TestCase):
  5
+    """
  6
+    Tests for URL handling in views and responses.
  7
+    """
  8
+    def test_iri_redirect(self):
  9
+        """
  10
+        Tests that redirecting to an IRI, requiring encoding before we use it
  11
+        in an HTTP response, is handled correctly.
  12
+        """
  13
+        response = self.client.get(u'/views/中文/')
  14
+        self.assertRedirects(response, "/views/%E4%B8%AD%E6%96%87/target/")
  15
+
5  tests/regressiontests/views/urls.py
... ...
@@ -1,3 +1,4 @@
  1
+# coding: utf-8
1 2
 from os import path
2 3
 
3 4
 from django.conf.urls.defaults import *
@@ -38,6 +39,10 @@
38 39
 
39 40
     # Static views
40 41
     (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': media_dir}),
  42
+
  43
+    # Special URLs for particular regression cases.
  44
+    url(u'^中文/$', 'regressiontests.views.views.redirect'),
  45
+    url(u'^中文/target/$', 'regressiontests.views.views.index_page'),
41 46
 )
42 47
 
43 48
 # Date-based generic views.
9  tests/regressiontests/views/views.py
... ...
@@ -1,4 +1,4 @@
1  
-from django.http import HttpResponse
  1
+from django.http import HttpResponse, HttpResponseRedirect
2 2
 from django import forms
3 3
 from django.views.generic.create_update import create_object
4 4
 
@@ -27,3 +27,10 @@ def save(self, *args, **kwargs):
27 27
     return create_object(request,
28 28
         post_save_redirect='/views/create_update/view/article/%(slug)s/',
29 29
         form_class=SlugChangingArticleForm)
  30
+
  31
+def redirect(request):
  32
+    """
  33
+    Forces an HTTP redirect.
  34
+    """
  35
+    return HttpResponseRedirect("target/")
  36
+

0 notes on commit 6771f4e

Please sign in to comment.
Something went wrong with that request. Please try again.