From bb4e17790e68df192a886349c7ecfc745a6c8ad4 Mon Sep 17 00:00:00 2001 From: qq213539 <213539@qq.com> Date: Tue, 8 Sep 2020 09:04:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9A=90=E6=82=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/alibaba/nacos/common/utils/IpUtil.java | 4 ++-- .../src/main/java/com/alibaba/nacos/naming/core/Instance.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/alibaba/nacos/common/utils/IpUtil.java b/common/src/main/java/com/alibaba/nacos/common/utils/IpUtil.java index e4f753c6ff7..97b3038ba21 100644 --- a/common/src/main/java/com/alibaba/nacos/common/utils/IpUtil.java +++ b/common/src/main/java/com/alibaba/nacos/common/utils/IpUtil.java @@ -40,14 +40,14 @@ public class IpUtil { public static final String IP_PORT_SPLITER = ":"; + public static final int SPLIT_IP_PORT_RESULT_LENGTH = 2; + private static final String LOCAL_HOST_IP_V4 = "127.0.0.1"; private static final String LOCAL_HOST_IP_V6 = "[::1]"; private static Pattern ipv4Pattern = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"); - private static final int SPLIT_IP_PORT_RESULT_LENGTH = 2; - private static final int IPV4_ADDRESS_LENGTH = 4; private static final int IPV6_ADDRESS_LENGTH = 16; diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/Instance.java b/naming/src/main/java/com/alibaba/nacos/naming/core/Instance.java index 121b6935f97..5a68dbb3f97 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/Instance.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/Instance.java @@ -123,7 +123,7 @@ public static Instance fromString(String config) { } int port = 0; - if (NumberUtils.isNumber(providerAddr[1])) { + if (providerAddr.length == IpUtil.SPLIT_IP_PORT_RESULT_LENGTH && NumberUtils.isNumber(providerAddr[1])) { port = Integer.parseInt(providerAddr[1]); }