File tree 1 file changed +6
-14
lines changed
1 file changed +6
-14
lines changed Original file line number Diff line number Diff line change 30
30
31
31
RAISE_ERROR = object ()
32
32
host_validation_re = _lazy_re_compile (
33
- r"^([a-z0-9.-]+|\[[a-f0-9]*:[a-f0-9\ .:]+\])(: [0-9]+)?$"
33
+ r"^([a-z0-9.-]+|\[[a-f0-9]*:[a-f0-9.:]+\])(?::( [0-9]+) )?$"
34
34
)
35
35
36
36
@@ -698,19 +698,11 @@ def split_domain_port(host):
698
698
Returned domain is lowercased. If the host is invalid, the domain will be
699
699
empty.
700
700
"""
701
- host = host .lower ()
702
-
703
- if not host_validation_re .match (host ):
704
- return "" , ""
705
-
706
- if host [- 1 ] == "]" :
707
- # It's an IPv6 address without a port.
708
- return host , ""
709
- bits = host .rsplit (":" , 1 )
710
- domain , port = bits if len (bits ) == 2 else (bits [0 ], "" )
711
- # Remove a trailing dot (if present) from the domain.
712
- domain = domain .removesuffix ("." )
713
- return domain , port
701
+ if match := host_validation_re .fullmatch (host .lower ()):
702
+ domain , port = match .groups (default = "" )
703
+ # Remove a trailing dot (if present) from the domain.
704
+ return domain .removesuffix ("." ), port
705
+ return "" , ""
714
706
715
707
716
708
def validate_host (host , allowed_hosts ):
You can’t perform that action at this time.
0 commit comments