Skip to content

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
@l4AgXc

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

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions