]> git.lizzy.rs Git - rust.git/commitdiff
rollup merge of #23097: alexcrichton/issue-23076
authorAlex Crichton <alex@alexcrichton.com>
Fri, 6 Mar 2015 23:37:56 +0000 (15:37 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 6 Mar 2015 23:37:56 +0000 (15:37 -0800)
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

src/libstd/net/addr.rs

index 916abe78eb3b3aeaf66c0c8cf166a9f7e84ebe1c..d975369af4940888878644d06b8dc1422ce1dab4 100644 (file)
@@ -293,7 +293,7 @@ macro_rules! try_opt {
         }
 
         // 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 @@ fn to_socket_addr_str() {
         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());
+    }
 }