mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #27181 -- Allowed contrib.sites to match domains with trailing ".".
This commit is contained in:
committed by
Tim Graham
parent
95627cb0aa
commit
05d2c5a66d
@@ -46,8 +46,6 @@ class SiteManager(models.Manager):
|
||||
except Site.DoesNotExist:
|
||||
# Fallback to looking up site after stripping port from the host.
|
||||
domain, port = split_domain_port(host)
|
||||
if not port:
|
||||
raise
|
||||
if domain not in SITE_CACHE:
|
||||
SITE_CACHE[domain] = self.get(domain__iexact=domain)
|
||||
return SITE_CACHE[domain]
|
||||
|
||||
@@ -554,9 +554,10 @@ def split_domain_port(host):
|
||||
# It's an IPv6 address without a port.
|
||||
return host, ''
|
||||
bits = host.rsplit(':', 1)
|
||||
if len(bits) == 2:
|
||||
return tuple(bits)
|
||||
return bits[0], ''
|
||||
domain, port = bits if len(bits) == 2 else (bits[0], '')
|
||||
# Remove a trailing dot (if present) from the domain.
|
||||
domain = domain[:-1] if domain.endswith('.') else domain
|
||||
return domain, port
|
||||
|
||||
|
||||
def validate_host(host, allowed_hosts):
|
||||
@@ -574,8 +575,6 @@ def validate_host(host, allowed_hosts):
|
||||
|
||||
Return ``True`` for a valid host, ``False`` otherwise.
|
||||
"""
|
||||
host = host[:-1] if host.endswith('.') else host
|
||||
|
||||
for pattern in allowed_hosts:
|
||||
if pattern == '*' or is_same_domain(host, pattern):
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user