MCPcopy
hub / github.com/django/django / is_same_domain

Function is_same_domain

django/utils/http.py:225–242  ·  view source on GitHub ↗

Return ``True`` if the host is either an exact match or a match to the wildcard pattern. Any pattern beginning with a period matches a domain and all of its subdomains. (e.g. ``.example.com`` matches ``example.com`` and ``foo.example.com``). Anything else is an exact string mat

(host, pattern)

Source from the content-addressed store, hash-verified

223
224
225def is_same_domain(host, pattern):
226 """
227 Return ``True`` if the host is either an exact match or a match
228 to the wildcard pattern.
229
230 Any pattern beginning with a period matches a domain and all of its
231 subdomains. (e.g. ``.example.com`` matches ``example.com`` and
232 ``foo.example.com``). Anything else is an exact string match.
233 """
234 if not pattern:
235 return False
236
237 pattern = pattern.lower()
238 return (
239 pattern[0] == "."
240 and (host.endswith(pattern) or host == pattern[1:])
241 or pattern == host
242 )
243
244
245def url_has_allowed_host_and_scheme(url, allowed_hosts, require_https=False):

Callers 5

_origin_verifiedMethod · 0.90
_check_refererMethod · 0.90
validate_hostFunction · 0.90
test_goodMethod · 0.90
test_badMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_goodMethod · 0.72
test_badMethod · 0.72