logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1557869 - in /logging/log4j/log4j2/trunk/log4j-core/src: main/java/org/apache/logging/log4j/core/jmx/Server.java test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
Date Mon, 13 Jan 2014 22:00:17 GMT
Author: rpopma
Date: Mon Jan 13 22:00:17 2014
New Revision: 1557869

URL: http://svn.apache.org/r1557869
Log:
LOG4J2-492 additional fix to handle line feed and carriage return characters in ObjectName
value

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java?rev=1557869&r1=1557868&r2=1557869&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
Mon Jan 13 22:00:17 2014
@@ -87,6 +87,14 @@ public final class Server {
                 // no need to escape these, but value must be quoted
                 needsQuotes = true;
                 break;
+            case '\r':
+                // replace by \\r, no need to quote
+                sb.append("\\r");
+                continue;
+            case '\n':
+                // replace by \\n, no need to quote
+                sb.append("\\n");
+                continue;
             }
             sb.append(c);
         }

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java?rev=1557869&r1=1557868&r2=1557869&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
Mon Jan 13 22:00:17 2014
@@ -90,4 +90,31 @@ public class ServerTest {
         new ObjectName(String.format(LoggerContextAdminMBean.PATTERN, ctxName)); 
         // no MalformedObjectNameException = success
     }
+
+    @Test
+    public void testEscapeIgnoresSpaces() throws Exception {
+        final String ctx = "a c";
+        final String ctxName = Server.escape(ctx);
+        assertEquals("a c", ctxName);
+        new ObjectName(String.format(LoggerContextAdminMBean.PATTERN, ctxName)); 
+        // no MalformedObjectNameException = success
+    }
+
+    @Test
+    public void testEscapeEscapesLineFeed() throws Exception {
+        final String ctx = "a\rc";
+        final String ctxName = Server.escape(ctx);
+//        assertEquals("a\\rc", ctxName);
+        new ObjectName(String.format(LoggerContextAdminMBean.PATTERN, ctxName)); 
+        // no MalformedObjectNameException = success
+    }
+
+    @Test
+    public void testEscapeEscapesCarriageReturn() throws Exception {
+        final String ctx = "a\nc";
+        final String ctxName = Server.escape(ctx);
+//        assertEquals("a\\nc", ctxName);
+        new ObjectName(String.format(LoggerContextAdminMBean.PATTERN, ctxName)); 
+        // no MalformedObjectNameException = success
+    }
 }



Mime
View raw message