From 8b55a4bd64dc9b7869830bbd0edd346d62060174 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Tue, 13 Dec 2022 16:55:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E8=BE=93=E5=87=BA=E4=BF=AE=E5=A4=8D,=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2$=E5=BC=95=E5=8F=91=E7=9A=84Illegal=20group=20referenc?= =?UTF-8?q?e=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/Util.java | 4 ++-- src/test/java/youhong/ai/pcn/TestOrganization.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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