rollup merge of #23097: alexcrichton/issue-23076

The `rsplitn` call was called with 2 instead of 1 so the iterator would yield 3
items in some cases, not the 2 that it should have.

Closes #23076
This commit is contained in:
Alex Crichton 2015-03-06 15:37:56 -08:00
commit 3c2c516d0c

View file

@ -293,7 +293,7 @@ impl ToSocketAddrs for str {
}
// split the string by ':' and convert the second part to u16
let mut parts_iter = self.rsplitn(2, ':');
let mut parts_iter = self.rsplitn(1, ':');
let port_str = try_opt!(parts_iter.next(), "invalid socket address");
let host = try_opt!(parts_iter.next(), "invalid socket address");
let port: u16 = try_opt!(port_str.parse().ok(), "invalid port value");
@ -590,4 +590,9 @@ mod tests {
let a = SocketAddr::new(IpAddr::new_v4(127, 0, 0, 1), 23924);
assert!(tsa("localhost:23924").unwrap().contains(&a));
}
#[test]
fn to_socket_addr_str_bad() {
assert!(tsa("1200::AB00:1234::2552:7777:1313:34300").is_err());
}
}