提交 f969222d 编写于 作者: clevertension's avatar clevertension

fix Illegal group reference

上级 4a874676
...@@ -4,6 +4,8 @@ import java.io.ByteArrayOutputStream; ...@@ -4,6 +4,8 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.regex.Matcher;
import org.skywalking.apm.agent.core.conf.Config; import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.conf.Constants; import org.skywalking.apm.agent.core.conf.Constants;
import org.skywalking.apm.logging.ILog; import org.skywalking.apm.logging.ILog;
...@@ -35,8 +37,10 @@ public class EasyLogger implements ILog { ...@@ -35,8 +37,10 @@ public class EasyLogger implements ILog {
if (parametersIndex >= parameters.length) { if (parametersIndex >= parameters.length) {
break; break;
} }
/**
tmpMessage = tmpMessage.replaceFirst("\\{\\}", String.valueOf(parameters[parametersIndex++])); * @Fix the Illegal group reference issue
*/
tmpMessage = tmpMessage.replaceFirst("\\{\\}", Matcher.quoteReplacement(String.valueOf(parameters[parametersIndex++])));
startSize = index + 2; startSize = index + 2;
} }
return tmpMessage; return tmpMessage;
......
...@@ -53,6 +53,34 @@ public class EasyLoggerTest { ...@@ -53,6 +53,34 @@ public class EasyLoggerTest {
.println(anyString()); .println(anyString());
} }
@Test
public void testLogWithSpecialChar() {
PrintStream output = Mockito.mock(PrintStream.class);
System.setOut(output);
PrintStream err = Mockito.mock(PrintStream.class);
System.setErr(err);
EasyLogger logger = new EasyLogger(EasyLoggerTest.class);
Assert.assertTrue(logger.isDebugEnable());
Assert.assertTrue(logger.isInfoEnable());
Assert.assertTrue(logger.isWarnEnable());
Assert.assertTrue(logger.isErrorEnable());
logger.debug("$$$$");
logger.debug("hello {}", "$$$$");
logger.info("{}{}");
logger.info("hello {}", "{}{}");
logger.warn("hello {}", "\\");
logger.warn("hello \\");
logger.error("hello <>..");
logger.error("hello ///\\\\", new NullPointerException());
logger.error(new NullPointerException(), "hello {}", "&&&**%%");
Mockito.verify(output, times(9))
.println(anyString());
}
@Test @Test
public void testFormat() { public void testFormat() {
NullPointerException exception = new NullPointerException(); NullPointerException exception = new NullPointerException();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册