Ticket #7494: fix_absolute_url_check_with_tests.diff

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

Updated patch including tests

  • django/http/__init__.py

     
    11import os
     2import re
    23from Cookie import SimpleCookie, CookieError
    34from pprint import pformat
    45from urllib import urlencode
     
    1819
    1920RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
    2021
     22absolute_http_url_re = re.compile(r"^https?://", re.I)
     23
    2124class Http404(Exception):
    2225    pass
    2326
     
    6568        """
    6669        if not location:
    6770            location = self.get_full_path()
    68         if not ':' in location:
     71        if not absolute_http_url_re.match(location):
    6972            current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http',
    7073                                         self.get_host(), self.path)
    7174            location = urljoin(current_uri, location)
  • tests/regressiontests/requests/tests.py

     
    3636>>> from django.http import parse_cookie
    3737>>> parse_cookie('invalid:key=true')
    3838{}
     39
     40>>> request = HttpRequest()
     41>>> print request.build_absolute_uri(location="https://www.example.com/asdf")
     42https://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")
     46http://www.example.com/path/with:colons
    3947"""
Back to Top