Code

Ticket #7494: fix_absolute_url_check_with_tests.diff

File fix_absolute_url_check_with_tests.diff, 1.5 KB (added by RobotAdam, 6 years ago)

Updated patch including tests

Line 
1Index: django/http/__init__.py
2===================================================================
3--- django/http/__init__.py     (revision 8466)
4+++ django/http/__init__.py     (working copy)
5@@ -1,4 +1,5 @@
6 import os
7+import re
8 from Cookie import SimpleCookie, CookieError
9 from pprint import pformat
10 from urllib import urlencode
11@@ -18,6 +19,8 @@
12 
13 RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
14 
15+absolute_http_url_re = re.compile(r"^https?://", re.I)
16+
17 class Http404(Exception):
18     pass
19 
20@@ -65,7 +68,7 @@
21         """
22         if not location:
23             location = self.get_full_path()
24-        if not ':' in location:
25+        if not absolute_http_url_re.match(location):
26             current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http',
27                                          self.get_host(), self.path)
28             location = urljoin(current_uri, location)
29Index: tests/regressiontests/requests/tests.py
30===================================================================
31--- tests/regressiontests/requests/tests.py     (revision 8466)
32+++ tests/regressiontests/requests/tests.py     (working copy)
33@@ -36,4 +36,12 @@
34 >>> from django.http import parse_cookie
35 >>> parse_cookie('invalid:key=true')
36 {}
37+
38+>>> request = HttpRequest()
39+>>> print request.build_absolute_uri(location="https://www.example.com/asdf")
40+https://www.example.com/asdf
41+>>> request.get_host = lambda: 'www.example.com'
42+>>> request.path = ''
43+>>> print request.build_absolute_uri(location="/path/with:colons")
44+http://www.example.com/path/with:colons
45 """