Skip to content

Commit fa1f4aa

Browse files
committed
Fix for issue #1
Bump version to 2.0.9
1 parent 20e3852 commit fa1f4aa

File tree

9 files changed

+56
-18
lines changed

9 files changed

+56
-18
lines changed

cf-java-logging-support-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>com.sap.hcp.cf.logging</groupId>
2626
<artifactId>cf-java-logging-support-parent</artifactId>
27-
<version>2.0.8</version>
27+
<version>2.0.9</version>
2828
<relativePath>../pom.xml</relativePath>
2929
</parent>
3030
<profiles>

cf-java-logging-support-core/src/main/java/com/sap/hcp/cf/logging/common/converter/DefaultMessageConverter.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ public class DefaultMessageConverter {
1111

1212
private boolean flatten = false;
1313
private boolean escape = false;
14-
private static Pattern OBJ_PATTERN = Pattern.compile("\\s*\\{([^}]+)}");
15-
private static Pattern ARRAY_PATTERN = Pattern.compile("\\s*\\[([^\\]]+)]");
16-
14+
private static final String LBRACE = "{";
15+
private static final String RBRACE = "}";
16+
private static final String LBRACKET = "[";
17+
private static final String RBRACKET = "]";
18+
1719
public boolean isFlatten() {
1820
return flatten;
1921
}
@@ -52,13 +54,13 @@ public void convert(String message, StringBuilder appendTo) {
5254
}
5355

5456
private String flattenMsg(String msg) {
55-
Matcher m = OBJ_PATTERN.matcher(msg);
56-
if (m.matches()) {
57-
return m.group(1);
57+
String trimmedMsg = msg.trim();
58+
59+
if (trimmedMsg.indexOf(LBRACE) == 0 && trimmedMsg.lastIndexOf(RBRACE) == trimmedMsg.length()-1) {
60+
return trimmedMsg.substring(1, trimmedMsg.length()-1);
5861
}
59-
m = ARRAY_PATTERN.matcher(msg);
60-
if (m.matches()) {
61-
return m.group(1);
62+
if (trimmedMsg.indexOf(LBRACKET) == 0 && trimmedMsg.lastIndexOf(RBRACKET) == trimmedMsg.length()-1) {
63+
return trimmedMsg.substring(1, trimmedMsg.length()-1);
6264
}
6365
return msg;
6466
}

cf-java-logging-support-core/src/test/java/com/sap/hcp/cf/logging/common/converter/TestJsonMessageConverter.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,43 @@ public void testLogRecordMsgFlattened() {
7373
public void testEscapedMessage() {
7474
DefaultMessageConverter jmc = new DefaultMessageConverter();
7575
String strangeMsg = TEST_MSG_NO_ARGS + STRANGE_SEQ;
76-
assertThat(formatMsg(jmc,strangeMsg), is(strangeMsg));
77-
76+
assertThat(formatMsg(jmc,strangeMsg), is(strangeMsg));
7877
}
78+
79+
@Test
80+
public void testObjNestedBraces() {
81+
String nestedBracesMsg = "\"request\": \"/Foo(${bar})\"";
82+
String logMsg = " {" + nestedBracesMsg + "} ";
83+
DefaultMessageConverter jmc = new DefaultMessageConverter();
84+
jmc.setFlatten(true);
85+
assertThat(formatMsg(jmc,logMsg), is(nestedBracesMsg));
86+
}
87+
88+
@Test
89+
public void testObjIncompleteNestedBraces() {
90+
String nestedBracesMsg = "\"request\": \"/Foo(${bar)\"";
91+
String logMsg = " {" + nestedBracesMsg + "} ";
92+
DefaultMessageConverter jmc = new DefaultMessageConverter();
93+
jmc.setFlatten(true);
94+
assertThat(formatMsg(jmc,logMsg), is(nestedBracesMsg));
95+
}
96+
97+
@Test
98+
public void testInvalidObjNestedBraces() {
99+
String nestedBracesMsg = "\"request\": \"/Foo(${bar)\"";
100+
String logMsg = " {" + nestedBracesMsg;
101+
DefaultMessageConverter jmc = new DefaultMessageConverter();
102+
jmc.setFlatten(true);
103+
assertThat(formatMsg(jmc,logMsg), is(logMsg));
104+
}
105+
106+
@Test
107+
public void testObjNestedBrackets() {
108+
String nestedBracketsMsg = "\"request\", \"/Foo($[bar])\"";
109+
String logMsg = " [" + nestedBracketsMsg + "] ";
110+
DefaultMessageConverter jmc = new DefaultMessageConverter();
111+
jmc.setFlatten(true);
112+
assertThat(formatMsg(jmc,logMsg), is(nestedBracketsMsg));
113+
}
114+
79115
}

cf-java-logging-support-jersey/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<relativePath>../pom.xml</relativePath>
1010
<groupId>com.sap.hcp.cf.logging</groupId>
1111
<artifactId>cf-java-logging-support-parent</artifactId>
12-
<version>2.0.8</version>
12+
<version>2.0.9</version>
1313
</parent>
1414

1515
<name>cf-java-logging-support-jersey</name>

cf-java-logging-support-log4j2/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<relativePath>../pom.xml</relativePath>
1212
<groupId>com.sap.hcp.cf.logging</groupId>
1313
<artifactId>cf-java-logging-support-parent</artifactId>
14-
<version>2.0.8</version>
14+
<version>2.0.9</version>
1515
</parent>
1616

1717
<properties>

cf-java-logging-support-logback/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<relativePath>../pom.xml</relativePath>
1111
<groupId>com.sap.hcp.cf.logging</groupId>
1212
<artifactId>cf-java-logging-support-parent</artifactId>
13-
<version>2.0.8</version>
13+
<version>2.0.9</version>
1414
</parent>
1515

1616
<properties>

cf-java-logging-support-servlet/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>com.sap.hcp.cf.logging</groupId>
1111
<artifactId>cf-java-logging-support-parent</artifactId>
12-
<version>2.0.8</version>
12+
<version>2.0.9</version>
1313
<relativePath>../pom.xml</relativePath>
1414
</parent>
1515

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.sap.hcp.cf.logging</groupId>
66
<artifactId>cf-java-logging-support-parent</artifactId>
7-
<version>2.0.8</version>
7+
<version>2.0.9</version>
88
<packaging>pom</packaging>
99

1010
<name>Cloud Foundry Java logging support components</name>

sample/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.sap.hcp.cf.logging</groupId>
88
<artifactId>cf-java-logging-support-parent</artifactId>
9-
<version>2.0.8</version>
9+
<version>2.0.9</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

0 commit comments

Comments
 (0)