File tree Expand file tree Collapse file tree 1 file changed +25
-12
lines changed Expand file tree Collapse file tree 1 file changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -15,17 +15,30 @@ pub fn validate_port(port int) !u16 {
15
15
16
16
// split_address splits an address into its host name and its port
17
17
pub fn split_address (addr string ) ! (string , u16 ) {
18
- port := addr.all_after_last (':' ).int ()
19
- mut address := addr.all_before_last (':' )
20
-
21
- // TODO(emily): Maybe do some more checking here
22
- // to validate ipv6 address sanity?
23
-
24
- // RFC4038 - allow [::1]:port
25
- if address.len > 0 && address[0 ] == `[` && address[address.len - 1 ] == `]` {
26
- address = address[1 ..address.len - 1 ]
18
+ if _ := addr.index (']' ) {
19
+ // ipv6 brackets
20
+ address := addr.all_after ('[' ).all_before_last (']' )
21
+ port := addr.all_after_last (']:' ).int ()
22
+ p := validate_port (port)!
23
+ return address, p
24
+ } else if _ := addr.index ('::' ) {
25
+ // ipv6 host only ::1
26
+ if addr.all_before_last ('::' ) == '' {
27
+ return addr, 0
28
+ } else {
29
+ // addr:port
30
+ address := addr.all_before_last (':' )
31
+ port := addr.all_after_last (':' ).int ()
32
+ p := validate_port (port)!
33
+ return address, p
34
+ }
35
+ } else if _ := addr.index (':' ) {
36
+ // addr:port
37
+ address := addr.all_before_last (':' )
38
+ p := validate_port (addr.all_after_last (':' ).int ())!
39
+ return address, p
40
+ } else {
41
+ // addr only
42
+ return addr, 0
27
43
}
28
-
29
- p := validate_port (port)!
30
- return address, p
31
44
}
You can’t perform that action at this time.
0 commit comments