From 6a9b414315504bc36ca26696bc4dbf280c8fcb25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E7=A6=B9=E5=85=89?= Date: Thu, 1 Aug 2019 20:56:52 +0800 Subject: [PATCH] fix bug --- .../main/java/com/alibaba/nacos/api/common/Constants.java | 2 ++ .../java/com/alibaba/nacos/naming/core/ServiceManager.java | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/alibaba/nacos/api/common/Constants.java b/api/src/main/java/com/alibaba/nacos/api/common/Constants.java index e5d61a3fd..dbc558376 100644 --- a/api/src/main/java/com/alibaba/nacos/api/common/Constants.java +++ b/api/src/main/java/com/alibaba/nacos/api/common/Constants.java @@ -162,4 +162,6 @@ public class Constants { public static final String NULL_STRING = "null"; public static final String NUMBER_PATTERN = "^\\d+$"; + + public static final String ANY_PATTERN = ".*"; } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java index 2352b38e1..4535400ad 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java @@ -684,7 +684,11 @@ public class ServiceManager implements RecordListener { } if (StringUtils.isNotBlank(serviceName)) { - matchList = searchServices(namespaceId, ".*" + serviceName + ".*"); + StringJoiner regex = new StringJoiner(Constants.SERVICE_INFO_SPLITER); + for (String param : serviceName.split(Constants.SERVICE_INFO_SPLITER)) { + regex.add(StringUtils.isBlank(param) ? Constants.ANY_PATTERN : Constants.ANY_PATTERN + param + Constants.ANY_PATTERN); + } + matchList = searchServices(namespaceId, regex.toString()); } else { matchList = new ArrayList<>(chooseServiceMap(namespaceId).values()); }