diff options
author | Anton Samarchyan <desecho@gmail.com> | 2016-11-29 18:17:10 -0500 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-11-29 18:17:10 -0500 |
commit | 05d2c5a66dd72c26e5221855e08834a66c844399 (patch) | |
tree | 9c75bce12b1d9215c5a8ad23edbf6d092a78edb5 /django/http/request.py | |
parent | 95627cb0aae375cb5820f051dee768d764fc2e68 (diff) | |
download | django-05d2c5a66dd72c26e5221855e08834a66c844399.tar.gz |
Fixed #27181 -- Allowed contrib.sites to match domains with trailing ".".
Diffstat (limited to 'django/http/request.py')
-rw-r--r-- | django/http/request.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/django/http/request.py b/django/http/request.py index 83131d52c3..9ffcd23fbd 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -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 |