Merge pull request #482 from clevertension/my-main
fix Illegal group reference
This commit is contained in:
commit
1370f3ced0
|
|
@ -4,6 +4,8 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.conf.Constants;
|
||||
import org.skywalking.apm.logging.ILog;
|
||||
|
|
@ -35,8 +37,10 @@ public class EasyLogger implements ILog {
|
|||
if (parametersIndex >= parameters.length) {
|
||||
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;
|
||||
}
|
||||
return tmpMessage;
|
||||
|
|
|
|||
|
|
@ -53,6 +53,34 @@ public class EasyLoggerTest {
|
|||
.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
|
||||
public void testFormat() {
|
||||
NullPointerException exception = new NullPointerException();
|
||||
|
|
@ -60,7 +88,7 @@ public class EasyLoggerTest {
|
|||
String formatLines = logger.format(exception);
|
||||
String[] lines = formatLines.split(Constants.LINE_SEPARATOR);
|
||||
Assert.assertEquals("java.lang.NullPointerException", lines[1]);
|
||||
Assert.assertEquals("\tat org.skywalking.apm.agent.core.logging.EasyLoggerTest.testFormat(EasyLoggerTest.java:58)", lines[2]);
|
||||
Assert.assertEquals("\tat org.skywalking.apm.agent.core.logging.EasyLoggerTest.testFormat(EasyLoggerTest.java:86)", lines[2]);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
|
|
|||
Loading…
Reference in New Issue