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 6f9679c4ded..c87294fdf86 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 @@ -51,6 +51,9 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme public static final Pattern IP_PATTERN = Pattern.compile("(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}):?(\\d{1,5})?"); + public static final Pattern ONLY_DIGIT_AND_DOT + = Pattern.compile("(\\d|\\.)+"); + public static final String SPLITER = "_"; public Instance() { @@ -296,10 +299,11 @@ public String generateInstanceId() { } public boolean validate() { - - Matcher matcher = IP_PATTERN.matcher(getIp() + ":" + getPort()); - if (!matcher.matches()) { - return false; + if (onlyContainsDigitAndDot()) { + Matcher matcher = IP_PATTERN.matcher(getIp() + ":" + getPort()); + if (!matcher.matches()) { + return false; + } } if (getWeight() > MAX_WEIGHT_VALUE || getWeight() < MIN_WEIGHT_VALUE) { @@ -309,6 +313,11 @@ public boolean validate() { return true; } + private boolean onlyContainsDigitAndDot() { + Matcher matcher = ONLY_DIGIT_AND_DOT.matcher(getIp()); + return matcher.matches(); + } + @Override public int compareTo(Object o) { if (!(o instanceof Instance)) {