-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should "01.01.01.01" be parsed as legal IPv4 ? #61186
Labels
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Comments
jonas-schievink
added
the
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
label
May 25, 2019
It is definitely legal. Either Leetcode is wrong or the question doesn't suppose you to "cheat" with the standard library. $ ping 01.01.01.01
PING 01.01.01.01 (1.1.1.1): 56 data bytes >>> import ipaddress
>>> ipaddress.IPv4Address('01.01.01.01')
IPv4Address('1.1.1.1') package main
import (
"net"
"fmt"
)
func main() {
fmt.Println(net.ParseIP("01.01.01.01")) // prints 1.1.1.1
} |
Are we sure it is not parsed as octal? https://superuser.com/questions/857603/are-ip-addresses-with-and-without-leading-zeroes-the-same |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
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?
The text was updated successfully, but these errors were encountered: