@@ -1013,10 +1013,37 @@ def test_get_host_suggestion_of_allowed_host(self):
1013
1013
):
1014
1014
request .get_host ()
1015
1015
1016
- def test_split_domain_port_removes_trailing_dot (self ):
1017
- domain , port = split_domain_port ("example.com.:8080" )
1018
- self .assertEqual (domain , "example.com" )
1019
- self .assertEqual (port , "8080" )
1016
+ def test_split_domain_port (self ):
1017
+ for host , expected in [
1018
+ ("<invalid>" , ("" , "" )),
1019
+ ("<invalid>:8080" , ("" , "" )),
1020
+ ("example.com 8080" , ("" , "" )),
1021
+ ("example.com:invalid" , ("" , "" )),
1022
+ ("[::1]" , ("[::1]" , "" )),
1023
+ ("[::1]:8080" , ("[::1]" , "8080" )),
1024
+ ("[::ffff:127.0.0.1]" , ("[::ffff:127.0.0.1]" , "" )),
1025
+ ("[::ffff:127.0.0.1]:8080" , ("[::ffff:127.0.0.1]" , "8080" )),
1026
+ (
1027
+ "[1851:0000:3238:DEF1:0177:0000:0000:0125]" ,
1028
+ ("[1851:0000:3238:def1:0177:0000:0000:0125]" , "" ),
1029
+ ),
1030
+ (
1031
+ "[1851:0000:3238:DEF1:0177:0000:0000:0125]:8080" ,
1032
+ ("[1851:0000:3238:def1:0177:0000:0000:0125]" , "8080" ),
1033
+ ),
1034
+ ("127.0.0.1" , ("127.0.0.1" , "" )),
1035
+ ("127.0.0.1:8080" , ("127.0.0.1" , "8080" )),
1036
+ ("example.com" , ("example.com" , "" )),
1037
+ ("example.com:8080" , ("example.com" , "8080" )),
1038
+ ("example.com." , ("example.com" , "" )),
1039
+ ("example.com.:8080" , ("example.com" , "8080" )),
1040
+ ("xn--n28h.test" , ("xn--n28h.test" , "" )),
1041
+ ("xn--n28h.test:8080" , ("xn--n28h.test" , "8080" )),
1042
+ ("subdomain.example.com" , ("subdomain.example.com" , "" )),
1043
+ ("subdomain.example.com:8080" , ("subdomain.example.com" , "8080" )),
1044
+ ]:
1045
+ with self .subTest (host = host ):
1046
+ self .assertEqual (split_domain_port (host ), expected )
1020
1047
1021
1048
1022
1049
class BuildAbsoluteURITests (SimpleTestCase ):
0 commit comments