From 9c6615c33c010dd58c0265c244565c2dd9eb2db1 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 29 Feb 2024 18:42:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(cli):=20=E4=BF=AE=E5=A4=8Dargument=E5=92=8C?= =?UTF-8?q?environment=E4=B8=BA=E7=A9=BA=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/cli/runner/ServiceInfoWrapper.java | 15 --------------- .../cli/runner/SpringPropertiesEscapeHelper.java | 7 +++++++ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/ServiceInfoWrapper.java b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/ServiceInfoWrapper.java index 26b922e..d01a153 100644 --- a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/ServiceInfoWrapper.java +++ b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/ServiceInfoWrapper.java @@ -68,19 +68,4 @@ public class ServiceInfoWrapper { ", name='" + name + '\'' + '}'; } - - private Map escape(Map map) { - // https://github.com/spring-projects/spring-framework/issues/9628 - // spring boot 的配置文件没有办法转义 $,使用 $\{ -> ${ 来绕过一下 - return map.entrySet() - .stream() - .peek(entry -> { - if (entry.getValue() instanceof String) { - String key = entry.getKey(); - String value = (String) entry.getValue(); - entry.setValue(value.replace("$\\{", "${")); - } - }) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } } diff --git a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/SpringPropertiesEscapeHelper.java b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/SpringPropertiesEscapeHelper.java index 722b255..4a98b2e 100644 --- a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/SpringPropertiesEscapeHelper.java +++ b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/SpringPropertiesEscapeHelper.java @@ -1,5 +1,6 @@ package com.lanyuanxiaoyao.service.cli.runner; +import cn.hutool.core.util.ObjectUtil; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -18,6 +19,9 @@ public class SpringPropertiesEscapeHelper { * 使用 _ 代替 map key 的 . */ public static Map escapeMapKey(Map map) { + if (ObjectUtil.isEmpty(map)) { + return map; + } Map result = new HashMap<>(); for (Map.Entry entry : map.entrySet()) { result.put(entry.getKey().replaceAll("_", "."), entry.getValue()); @@ -28,6 +32,9 @@ public class SpringPropertiesEscapeHelper { public static Map escapeMapValue(Map map) { // https://github.com/spring-projects/spring-framework/issues/9628 // spring boot 的配置文件没有办法转义 $,使用 $\{ -> ${ 来绕过一下 + if (ObjectUtil.isEmpty(map)) { + return map; + } return map.entrySet() .stream() .peek(entry -> {