Merge pull request #2485 from y67h41/fix-/0-CIDR

Make /0 CIDR parsed as IP
This commit is contained in:
2dust
2023-09-01 22:33:13 +08:00
committed by GitHub
2 changed files with 3 additions and 1 deletions

View File

@@ -178,7 +178,7 @@ object Utils {
//CIDR
if (addr.indexOf("/") > 0) {
val arr = addr.split("/")
if (arr.count() == 2 && Integer.parseInt(arr[1]) > 0) {
if (arr.count() == 2 && Integer.parseInt(arr[1]) > -1) {
addr = arr[0]
}
}

View File

@@ -20,6 +20,7 @@ class UtilTest {
assertTrue(Utils.isIpAddress("127.0.0.1" ))
assertTrue(Utils.isIpAddress("127.0.0.1:80" ))
assertTrue(Utils.isIpAddress("0.0.0.0/0" ))
assertTrue(Utils.isIpAddress("::1" ))
assertTrue(Utils.isIpAddress("[::1]:80" ))
assertTrue(Utils.isIpAddress("2605:2700:0:3::4713:93e3" ))
@@ -28,6 +29,7 @@ class UtilTest {
assertTrue(Utils.isIpAddress("[::ffff:192.168.173.22]:80" ))
assertTrue(Utils.isIpAddress("1::" ))
assertTrue(Utils.isIpAddress("::" ))
assertTrue(Utils.isIpAddress("::/0" ))
assertTrue(Utils.isIpAddress("10.24.56.0/24" ))
assertTrue(Utils.isIpAddress("2001:4321::1" ))
assertTrue(Utils.isIpAddress("240e:1234:abcd:12::6666" ))