Author: mtredinnick
Date: 2009-04-11 22:50:47 -0500 (Sat, 11 Apr 2009)
New Revision: 10539

Added:
   django/trunk/tests/regressiontests/views/tests/specials.py
Modified:
   django/trunk/django/http/__init__.py
   django/trunk/tests/regressiontests/views/tests/__init__.py
   django/trunk/tests/regressiontests/views/urls.py
   django/trunk/tests/regressiontests/views/views.py
Log:
Fixed #10267 -- Correctly handle IRIs in HttpResponse.build_absolute_uri().

Modified: django/trunk/django/http/__init__.py
===================================================================
--- django/trunk/django/http/__init__.py        2009-04-12 02:50:41 UTC (rev 
10538)
+++ django/trunk/django/http/__init__.py        2009-04-12 03:50:47 UTC (rev 
10539)
@@ -72,7 +72,7 @@
             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"
@@ -398,14 +398,14 @@
 
     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

Modified: django/trunk/tests/regressiontests/views/tests/__init__.py
===================================================================
--- django/trunk/tests/regressiontests/views/tests/__init__.py  2009-04-12 
02:50:41 UTC (rev 10538)
+++ django/trunk/tests/regressiontests/views/tests/__init__.py  2009-04-12 
03:50:47 UTC (rev 10539)
@@ -1,6 +1,7 @@
+from debug import *
 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 *
-from debug import *

Added: django/trunk/tests/regressiontests/views/tests/specials.py
===================================================================
--- django/trunk/tests/regressiontests/views/tests/specials.py                  
        (rev 0)
+++ django/trunk/tests/regressiontests/views/tests/specials.py  2009-04-12 
03:50:47 UTC (rev 10539)
@@ -0,0 +1,15 @@
+# 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/")
+

Modified: django/trunk/tests/regressiontests/views/urls.py
===================================================================
--- django/trunk/tests/regressiontests/views/urls.py    2009-04-12 02:50:41 UTC 
(rev 10538)
+++ django/trunk/tests/regressiontests/views/urls.py    2009-04-12 03:50:47 UTC 
(rev 10539)
@@ -1,3 +1,4 @@
+# coding: utf-8
 from os import path
 
 from django.conf.urls.defaults import *
@@ -38,6 +39,10 @@
 
     # 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.

Modified: django/trunk/tests/regressiontests/views/views.py
===================================================================
--- django/trunk/tests/regressiontests/views/views.py   2009-04-12 02:50:41 UTC 
(rev 10538)
+++ django/trunk/tests/regressiontests/views/views.py   2009-04-12 03:50:47 UTC 
(rev 10539)
@@ -1,6 +1,6 @@
 import sys
 
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseRedirect
 from django import forms
 from django.views.debug import technical_500_response
 from django.views.generic.create_update import create_object
@@ -36,3 +36,10 @@
         raise Exception
     except Exception:
         return technical_500_response(request, *sys.exc_info())
+
+def redirect(request):
+    """
+    Forces an HTTP redirect.
+    """
+    return HttpResponseRedirect("target/")
+


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to