Skip to content

Should "01.01.01.01" be parsed as legal IPv4 ? #61186

Closed
@huangjj27

Description

@huangjj27

original problem: https://leetcode-cn.com/problems/validate-ip-address/
while std::net::IpAddr::parse successfully parse the address, but the leetcode problem doesn't regard the address as "legal",

test DEMO:

use std::net::IpAddr;

fn main() {
    if let Ok(IpAddr::V4(_)) = "01.01.01.01".parse() {
        println!("parsed!");  // it gets in!
    }
}

Usually, we consider IPv4 address containing only non-leading-zero number 0-255 legal, but not those with leading-zero numbers in. Should we change the behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    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