Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7494 -- Fixed build_absolute_url() for some types of (uncommon…

…) URLs.

Patch from tom@almostobsolete.net and RobotAdam.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8490 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 646f2f6101cda3e20908928de44739dfff596b0f 1 parent 3dd69a9
Malcolm Tredinnick authored August 23, 2008
5  django/http/__init__.py
... ...
@@ -1,4 +1,5 @@
1 1
 import os
  2
+import re
2 3
 from Cookie import SimpleCookie, CookieError
3 4
 from pprint import pformat
4 5
 from urllib import urlencode
@@ -18,6 +19,8 @@
18 19
 
19 20
 RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
20 21
 
  22
+absolute_http_url_re = re.compile(r"^https?://", re.I)
  23
+
21 24
 class Http404(Exception):
22 25
     pass
23 26
 
@@ -65,7 +68,7 @@ def build_absolute_uri(self, location=None):
65 68
         """
66 69
         if not location:
67 70
             location = self.get_full_path()
68  
-        if not ':' in location:
  71
+        if not absolute_http_url_re.match(location):
69 72
             current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http',
70 73
                                          self.get_host(), self.path)
71 74
             location = urljoin(current_uri, location)
8  tests/regressiontests/requests/tests.py
@@ -36,4 +36,12 @@
36 36
 >>> from django.http import parse_cookie
37 37
 >>> parse_cookie('invalid:key=true')
38 38
 {}
  39
+
  40
+>>> request = HttpRequest()
  41
+>>> print request.build_absolute_uri(location="https://www.example.com/asdf")
  42
+https://www.example.com/asdf
  43
+>>> request.get_host = lambda: 'www.example.com'
  44
+>>> request.path = ''
  45
+>>> print request.build_absolute_uri(location="/path/with:colons")
  46
+http://www.example.com/path/with:colons
39 47
 """

0 notes on commit 646f2f6

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