diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index 962df09..9e9a5dc 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -3082,7 +3082,7 @@ public class Util extends weaver.general.Util { if (arg instanceof Throwable) { for (int i = 0; i < args.length - 1; i++) { pattern = "\\{" + i + "}"; - logStr = logStr.replaceFirst(pattern, String.valueOf(args[i])); + logStr = logStr.replaceFirst(pattern, Matcher.quoteReplacement(String.valueOf(args[i]))); } return logStr + "\n" + getErrString((Throwable) arg); } @@ -3090,7 +3090,7 @@ public class Util extends weaver.general.Util { } for (int i = 0; i < args.length; i++) { pattern = "\\{" + i + "}"; - logStr = logStr.replaceFirst(pattern, String.valueOf(args[i])); + logStr = logStr.replaceFirst(pattern, Matcher.quoteReplacement(String.valueOf(args[i]))); } return logStr; } catch (Exception e) { diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java index 81c4f3b..dd9f2a5 100644 --- a/src/test/java/youhong/ai/pcn/TestOrganization.java +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -144,7 +144,8 @@ public class TestOrganization extends BaseTest { @Test public void testLogStr() { - System.out.println(Util.logStr("ajsdf {} jasjdf {}", "asf", "asdfeag")); + System.out.println(Util.logStr("ajsdf {} jasjdf {}", "{\"cus\":\"select? * fr$%&#@!)(<>?/\\\\「」【【】[]~、asfom table where id = '' and teset = #{name}\",\"sealSnCusSql\":\"select \\n? from jkfdjsfk where id \\n=1\",\"niua\":\"卧槽\",\"sealSnField\":\"sealSn\",\"sealNumField\":\"sealNum\",\"sealNumCusSql\":\"select case ? when 0 then htzyzcs when 1 then gzcs else frzcs end from formtable_main_22_dt1 where id = {?dt.id}\",\"hah\":\"liuliu\"} ")); + System.out.println("{0} {} ".replaceFirst("\\{0}", Matcher.quoteReplacement("{\"cus\":\"select? * fr$%&#@!)(<>?/\\\\「」【【】[]~、asfom table where id = '' and teset = #{name}\",\"sealSnCusSql\":\"select \\n? from jkfdjsfk where id \\n=1\",\"niua\":\"卧槽\",\"sealSnField\":\"sealSn\",\"sealNumField\":\"sealNum\",\"sealNumCusSql\":\"select case ? when 0 then htzyzcs when 1 then gzcs else frzcs end from formtable_main_22_dt1 where id = {?dt.id}\",\"hah\":\"liuliu\"} "))); } @Test