From feb4c098af22dbaf22e7d8d4d6689687169c6623 Mon Sep 17 00:00:00 2001 From: "nov.lzf" Date: Thu, 5 Sep 2024 13:58:48 +0800 Subject: [PATCH] fix labels from env (#12604) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复环境变量设置标签失效bug * pmd fix --- .../common/labels/impl/DefaultLabelsCollector.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/alibaba/nacos/common/labels/impl/DefaultLabelsCollector.java b/common/src/main/java/com/alibaba/nacos/common/labels/impl/DefaultLabelsCollector.java index f7d2a2dd69a..af2a57d38c9 100644 --- a/common/src/main/java/com/alibaba/nacos/common/labels/impl/DefaultLabelsCollector.java +++ b/common/src/main/java/com/alibaba/nacos/common/labels/impl/DefaultLabelsCollector.java @@ -44,6 +44,8 @@ public class DefaultLabelsCollector implements LabelsCollector { private static final String UNDERSCORE = "_"; + private static final String ESCAPE = "\\"; + /** * init labels. * @@ -79,12 +81,12 @@ public Map collectLabels(Properties properties) { //env LOGGER.info("default nacos collect env raw labels: {}", - System.getenv(Constants.APP_CONN_LABELS_KEY.replaceAll(DOT, UNDERSCORE))); + System.getenv(Constants.APP_CONN_LABELS_KEY.replaceAll(ESCAPE + DOT, UNDERSCORE))); Map envLabels = ConnLabelsUtils.parseRawLabels( - System.getenv(Constants.APP_CONN_LABELS_KEY.replaceAll(DOT, UNDERSCORE))); - if (System.getenv(Constants.CONFIG_GRAY_LABEL.replaceAll(DOT, UNDERSCORE)) != null) { + System.getenv(Constants.APP_CONN_LABELS_KEY.replaceAll(ESCAPE + DOT, UNDERSCORE))); + if (System.getenv(Constants.CONFIG_GRAY_LABEL.replaceAll(ESCAPE + DOT, UNDERSCORE)) != null) { envLabels.put(Constants.CONFIG_GRAY_LABEL, - System.getenv(Constants.CONFIG_GRAY_LABEL.replaceAll(DOT, UNDERSCORE))); + System.getenv(Constants.CONFIG_GRAY_LABEL.replaceAll(ESCAPE + DOT, UNDERSCORE))); } LOGGER.info("default nacos collect env labels: {}", envLabels);