diff --git a/common/src/main/java/io/seata/common/util/NetAddressValidatorUtil.java b/common/src/main/java/io/seata/common/util/NetAddressValidatorUtil.java index 9884a3afb77..00f8b53d90c 100644 --- a/common/src/main/java/io/seata/common/util/NetAddressValidatorUtil.java +++ b/common/src/main/java/io/seata/common/util/NetAddressValidatorUtil.java @@ -38,7 +38,8 @@ public class NetAddressValidatorUtil { private static final int FIVE = 5; - private static final Pattern IPV4_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$"); + private static final Pattern IPV4_PATTERN = Pattern + .compile("^" + "(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)" + "(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}" + "$"); private static final Pattern IPV6_STD_PATTERN = Pattern .compile("^" + "(?:[0-9a-fA-F]{1,4}:){7}" + "[0-9a-fA-F]{1,4}" + "$"); diff --git a/common/src/test/java/io/seata/common/util/NetAddressValidatorUtilTest.java b/common/src/test/java/io/seata/common/util/NetAddressValidatorUtilTest.java index 5e50ec8216c..b274855cf1f 100644 --- a/common/src/test/java/io/seata/common/util/NetAddressValidatorUtilTest.java +++ b/common/src/test/java/io/seata/common/util/NetAddressValidatorUtilTest.java @@ -50,5 +50,7 @@ public void isIPv6IPv4MappedAddress() { @Test public void isIPv4Address() { assertThat(NetAddressValidatorUtil.isIPv4Address("192.168.1.2")).isTrue(); + assertThat(NetAddressValidatorUtil.isIPv4Address("127.0.0.1")).isTrue(); + assertThat(NetAddressValidatorUtil.isIPv4Address("999.999.999.999")).isFalse(); } }