add null check to format string
Change-Id: If82f751ec679189620e02fafdcd2e1af9258268f
Issue-ID: CCSDK-424
Signed-off-by: Smokowski, Kevin (ks6305) <ks6305@att.com>
}
protected String formatString(String str) {
- str = str.replaceAll("\\R",""); // this will strip all new line characters
- str = str.replaceAll("\\|","%7C"); //log records should not contain a pipe, encode the pipe character
- return str;
+ if (str != null) {
+ str = str.replaceAll("\\R", ""); // this will strip all new line characters
+ str = str.replaceAll("\\|", "%7C"); // log records should not contain a pipe, encode the pipe character
+ }
+ return str;
}
public static void resetContext() {
logger.asIso8601(System.currentTimeMillis());
}
-
-
+ @Test
+ public void formatString() {
+ String output = logger.formatString("\n");
+ assertEquals("",output);
+ output = logger.formatString("|");
+ assertEquals("%7C",output);
+ output = logger.formatString(null);
+ assertEquals(null,output);
+ }
}