From 0b057820dbfb62ca50415fae356af9261844beea Mon Sep 17 00:00:00 2001 From: chengpu Date: Fri, 17 Feb 2023 16:26:36 +0800 Subject: [PATCH] fix: remove useless suffix of IPv6 address. --- .../java/com/alibaba/cloud/nacos/util/InetIPv6Utils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/util/InetIPv6Utils.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/util/InetIPv6Utils.java index 6c432107e..740c44105 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/util/InetIPv6Utils.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/util/InetIPv6Utils.java @@ -96,7 +96,10 @@ public class InetIPv6Utils { } private String normalizeIPv6(String ip) { - return "[" + ip + "]"; + // Remove the suffix of network card in IPv6 address, such as + // 2408:400a:8c:5400:6578:5c42:77b1:bc5d%eth0 + int idx = ip.indexOf("%"); + return idx != -1 ? "[" + ip.substring(0, idx) + "]" : "[" + ip + "]"; } private boolean isPreferredAddress(InetAddress address) {