std::net::Ipv6Addr::from_str
accepts "::f:f:f:f:f:f:f:f"
but rejects "f:f:f:f:f:f:f:f::"
#46263
Closed
Description
When all eight segments are present in an IPv6 address specification, std::net::Ipv6Addr::from_str
allows ::
anywhere, except at the very end.
Here is a test program:
use std::net;
fn main() {
let tests = [
"::f:f:f:f:f:f:f:f",
"f::f:f:f:f:f:f:f",
"f:f::f:f:f:f:f:f",
"f:f:f::f:f:f:f:f",
"f:f:f:f::f:f:f:f",
"f:f:f:f:f::f:f:f",
"f:f:f:f:f:f::f:f",
"f:f:f:f:f:f:f::f",
"f:f:f:f:f:f:f:f::",
];
for test in tests.iter() {
match test.parse::<net::Ipv6Addr>() {
Ok(addr) => println!("{:?}\t{}", test, addr),
Err(err) => println!("{:?}\t{}", test, err),
}
}
}
The output is:
"::f:f:f:f:f:f:f:f" f:f:f:f:f:f:f:f
"f::f:f:f:f:f:f:f" f:f:f:f:f:f:f:f
"f:f::f:f:f:f:f:f" f:f:f:f:f:f:f:f
"f:f:f::f:f:f:f:f" f:f:f:f:f:f:f:f
"f:f:f:f::f:f:f:f" f:f:f:f:f:f:f:f
"f:f:f:f:f::f:f:f" f:f:f:f:f:f:f:f
"f:f:f:f:f:f::f:f" f:f:f:f:f:f:f:f
"f:f:f:f:f:f:f::f" f:f:f:f:f:f:f:f
"f:f:f:f:f:f:f:f::" invalid IP address syntax
Meta
rustc 1.21.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.21.0
LLVM version: 4.0