mirror of
https://github.com/django/django.git
synced 2025-05-30 02:36:29 +00:00
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
This commit is contained in:
parent
3dd69a965b
commit
646f2f6101
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from Cookie import SimpleCookie, CookieError
|
from Cookie import SimpleCookie, CookieError
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
@ -18,6 +19,8 @@ from utils import *
|
|||||||
|
|
||||||
RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
|
RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
|
||||||
|
|
||||||
|
absolute_http_url_re = re.compile(r"^https?://", re.I)
|
||||||
|
|
||||||
class Http404(Exception):
|
class Http404(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -65,7 +68,7 @@ class HttpRequest(object):
|
|||||||
"""
|
"""
|
||||||
if not location:
|
if not location:
|
||||||
location = self.get_full_path()
|
location = self.get_full_path()
|
||||||
if not ':' in location:
|
if not absolute_http_url_re.match(location):
|
||||||
current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http',
|
current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http',
|
||||||
self.get_host(), self.path)
|
self.get_host(), self.path)
|
||||||
location = urljoin(current_uri, location)
|
location = urljoin(current_uri, location)
|
||||||
|
@ -36,4 +36,12 @@ META:{}>
|
|||||||
>>> from django.http import parse_cookie
|
>>> from django.http import parse_cookie
|
||||||
>>> parse_cookie('invalid:key=true')
|
>>> parse_cookie('invalid:key=true')
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
>>> request = HttpRequest()
|
||||||
|
>>> print request.build_absolute_uri(location="https://www.example.com/asdf")
|
||||||
|
https://www.example.com/asdf
|
||||||
|
>>> request.get_host = lambda: 'www.example.com'
|
||||||
|
>>> request.path = ''
|
||||||
|
>>> print request.build_absolute_uri(location="/path/with:colons")
|
||||||
|
http://www.example.com/path/with:colons
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user