Skip to content

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

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions