[Bug]: utils.IsIPv4 and net.ParseIP have inconsistent results #2735 (#2736)

pull/2739/head
Jmper 2023-11-21 17:48:37 +08:00 committed by GitHub
parent 2374cad3cd
commit 2c5d883a69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View File

@ -23,7 +23,7 @@ func IsIPv4(s string) bool {
for ci = 0; ci < len(s) && '0' <= s[ci] && s[ci] <= '9'; ci++ {
n = n*10 + int(s[ci]-'0')
if n >= 0xFF {
if n > 0xFF {
return false
}
}

View File

@ -14,6 +14,7 @@ func Test_IsIPv4(t *testing.T) {
AssertEqual(t, true, IsIPv4("174.23.33.100"))
AssertEqual(t, true, IsIPv4("127.0.0.1"))
AssertEqual(t, true, IsIPv4("127.255.255.255"))
AssertEqual(t, true, IsIPv4("0.0.0.0"))
AssertEqual(t, false, IsIPv4(".0.0.0"))