mirror of https://github.com/gofiber/fiber.git
🚨 added testcases and minor algorithm improvment (#2308)
* Deleted redundant check for an ipv4 address octet block that is bigger than 255 in utils/ip.go. Also added a testcase for octetblocks that are bigger than 255. * Added extra testcasespull/2312/head
parent
66cc869b1f
commit
e2cb81ddd3
|
@ -1,6 +1,8 @@
|
|||
package utils
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
)
|
||||
|
||||
// IsIPv4 works the same way as net.ParseIP,
|
||||
// but without check for IPv6 case and without returning net.IP slice, whereby IsIPv4 makes no allocations.
|
||||
|
@ -26,7 +28,7 @@ func IsIPv4(s string) bool {
|
|||
}
|
||||
}
|
||||
|
||||
if ci == 0 || n > 0xFF || (ci > 1 && s[0] == '0') {
|
||||
if ci == 0 || (ci > 1 && s[0] == '0') {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,11 @@ func Test_IsIPv4(t *testing.T) {
|
|||
AssertEqual(t, false, IsIPv4(""))
|
||||
AssertEqual(t, false, IsIPv4("2345:0425:2CA1::0567:5673:23b5"))
|
||||
AssertEqual(t, false, IsIPv4("invalid"))
|
||||
AssertEqual(t, false, IsIPv4("189.12.34.260"))
|
||||
AssertEqual(t, false, IsIPv4("189.12.260.260"))
|
||||
AssertEqual(t, false, IsIPv4("189.260.260.260"))
|
||||
AssertEqual(t, false, IsIPv4("999.999.999.999"))
|
||||
AssertEqual(t, false, IsIPv4("9999.9999.9999.9999"))
|
||||
}
|
||||
|
||||
// go test -v -run=^$ -bench=UnsafeString -benchmem -count=2
|
||||
|
|
Loading…
Reference in New Issue