Repository: logging-log4j2 Updated Branches: refs/heads/master e7bbeceb1 -> e9b628ec5
[LOG4J2-1069] Improper handling of JSON escape chars when deserializing JSON log events. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/e9b628ec Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/e9b628ec Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/e9b628ec Branch: refs/heads/master Commit: e9b628ec5d3c45a5fa6a1160119d15cf31d60138 Parents: e7bbece Author: ggregory <[email protected]> Authored: Thu Jun 25 12:11:03 2015 -0700 Committer: ggregory <[email protected]> Committed: Thu Jun 25 12:11:03 2015 -0700 ---------------------------------------------------------------------- .../core/net/server/JsonInputStreamLogEventBridge.java | 6 ++++-- .../log4j/core/net/server/AbstractSocketServerTest.java | 11 ++++++++++- src/changes/changes.xml | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e9b628ec/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/JsonInputStreamLogEventBridge.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/JsonInputStreamLogEventBridge.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/JsonInputStreamLogEventBridge.java index 1b81644..8ed2732 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/JsonInputStreamLogEventBridge.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/JsonInputStreamLogEventBridge.java @@ -55,8 +55,10 @@ public class JsonInputStreamLogEventBridge extends InputStreamLogEventBridge { boolean inEsc = false; for (int i = start; i < charArray.length; i++) { final char c = charArray[i]; - if (!inEsc) { - inEsc = false; + if (inEsc) { + // Skip this char and continue + inEsc = false; + } else { switch (c) { case EVENT_START_MARKER: if (!inStr) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e9b628ec/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java index 891e278..2bcdd43 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java @@ -69,7 +69,9 @@ public abstract class AbstractSocketServerTest { private static final String MESSAGE = "This is test message"; private static final String MESSAGE_2 = "This is test message 2"; - + + private static final String MESSAGE_WITH_SPECIAL_CHARS = "{This}\n[is]\"n\"a\"\r\ntrue:\n\ttest,\nmessage"; + static final int PORT_NUM = AvailablePortFinder.getNextAvailable(); static final String PORT = String.valueOf(PORT_NUM); @@ -158,6 +160,13 @@ public abstract class AbstractSocketServerTest { testServer(m1, m2); } } + + + @Test + public void testMessagesWithSpecialChars() throws Exception { + testServer(MESSAGE_WITH_SPECIAL_CHARS); + } + private void testServer(final int size) throws Exception { final String[] messages = new String[size]; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e9b628ec/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f4257d4..73af64a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -48,6 +48,9 @@ <action issue="LOG4J2-1051" dev="ggregory" type="fix" due-to="Lukasz Lenart"> NoClassDefFoundError when starting app on Google App Engine. </action> + <action issue="LOG4J2-1069" dev="ggregory" type="fix" due-to="Sam Braam"> + Improper handling of JSON escape chars when deserializing JSON log events. + </action> <action issue="LOG4J2-1068" dev="ggregory" type="fix" due-to="Andy McMullan"> Exceptions not logged when using TcpSocketServer + SerializedLayout. </action>
