From 2c8a525a16d5b71dc00f938e710486785f0ba7c8 Mon Sep 17 00:00:00 2001 From: Ifdevil <384867771@qq.com> Date: Sun, 8 Oct 2023 14:23:35 +0800 Subject: [PATCH] fix ipv4_pattern --- .../java/io/seata/common/util/NetAddressValidatorUtil.java | 3 ++- .../java/io/seata/common/util/NetAddressValidatorUtilTest.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) 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(); } }