summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net.rs38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/net.rs b/src/net.rs
index 2a7d64b861..70d585bba2 100644
--- a/src/net.rs
+++ b/src/net.rs
@@ -42,6 +42,8 @@ impl From<SocketAddr> for RemoteAddr {
impl FromStr for RemoteAddr {
type Err = AddrParseError;
+ /// Parse a string into a `RemoteAddr`. Does not work correctly with IPv6, see tests for
+ /// defined behavior
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (address_str, port_str) = split_at_colon(s).map_err(|_| AddrParseError::InvalidPort)?;
let port = u16::from_str(port_str).map_err(|_| AddrParseError::InvalidPort)?;
@@ -122,18 +124,32 @@ mod tests {
assert_eq!(3333, remote_addr.port());
}
- #[test]
- fn remote_addr_from_ipv6_str() {
- let remote_addr = RemoteAddr::from_str("[fe80::1]:1337").unwrap();
- assert_eq!("[fe80::1]", remote_addr.address());
- assert_eq!(1337, remote_addr.port());
- }
+ // These tests exist to show that the parsing does not work exactly as the standard suggests
+ // https://tools.ietf.org/html/rfc3986#appendix-A
+ mod ipv6_invalid_parsing {
+ use std::str::FromStr;
+ use super::super::*;
- #[test]
- fn remote_addr_from_ipv6_str_without_port() {
- let remote_addr = RemoteAddr::from_str("fe80::1").unwrap();
- assert_eq!("fe80:", remote_addr.address());
- assert_eq!(1, remote_addr.port());
+ #[test]
+ fn remote_addr_from_ipv6_str_without_brackets() {
+ let remote_addr = RemoteAddr::from_str("fe80::1:1337").unwrap();
+ assert_eq!("fe80::1", remote_addr.address());
+ assert_eq!(1337, remote_addr.port());
+ }
+
+ #[test]
+ fn remote_addr_from_ipv6_str_with_brackets() {
+ let remote_addr = RemoteAddr::from_str("[fe80::1]:1337").unwrap();
+ assert_eq!("[fe80::1]", remote_addr.address());
+ assert_eq!(1337, remote_addr.port());
+ }
+
+ #[test]
+ fn remote_addr_from_ipv6_str_without_port() {
+ let remote_addr = RemoteAddr::from_str("fe80::1").unwrap();
+ assert_eq!("fe80:", remote_addr.address());
+ assert_eq!(1, remote_addr.port());
+ }
}
#[test]