logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1482944 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/helpers/Charsets.java core/src/test/java/org/apache/logging/log4j/core/helpers/CharsetsTest.java src/changes/changes.xml
Date Wed, 15 May 2013 16:31:34 GMT
Author: rpopma
Date: Wed May 15 16:31:34 2013
New Revision: 1482944

URL: http://svn.apache.org/r1482944
Log:
LOG4J2-255 multi-byte character strings are now assumed to be in the default char encoding,
not utf-8. Added JUnit tests.

Added:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/helpers/CharsetsTest.java
  (with props)
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Charsets.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Charsets.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Charsets.java?rev=1482944&r1=1482943&r2=1482944&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Charsets.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Charsets.java
Wed May 15 16:31:34 2013
@@ -31,10 +31,12 @@ public final class Charsets {
     }
 
     /**
-     * Gets a Charset, starting with the preferred {@code charsetName} if supported, if not,
use UTF-8.
+     * Returns a Charset, if possible the Charset for the specified {@code charsetName},
+     * otherwise (if the specified {@code charsetName} is {@code null} or not supported)
+     * this method returns the platform default Charset.
      *
      * @param charsetName
-     *            the preferred charset name
+     *            name of the preferred charset or {@code null}
      * @return a Charset, not null.
      */
     public static Charset getSupportedCharset(final String charsetName) {
@@ -45,7 +47,7 @@ public final class Charsets {
             }
         }
         if (charset == null) {
-            charset = UTF_8;
+            charset = Charset.defaultCharset();
             if (charsetName != null) {
                 StatusLogger.getLogger().error("Charset " + charsetName + " is not supported
for layout, using " +
                     charset.displayName());

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/helpers/CharsetsTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/helpers/CharsetsTest.java?rev=1482944&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/helpers/CharsetsTest.java
(added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/helpers/CharsetsTest.java
Wed May 15 16:31:34 2013
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.helpers;
+
+import static org.junit.Assert.*;
+
+import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
+
+import org.junit.Test;
+
+public class CharsetsTest {
+
+    @Test
+    public void testReturnDefaultIfNameIsNull() {
+        Charset actual = Charsets.getSupportedCharset(null);
+        assertSame(Charset.defaultCharset(), actual);
+    }
+
+    @Test
+    public void testReturnDefaultIfNameIsUnsupported() {
+        Charset actual = Charsets.getSupportedCharset("INeedMoreSupport");
+        assertSame(Charset.defaultCharset(), actual);
+    }
+
+    @Test(expected=IllegalCharsetNameException.class)
+    public void testThrowsExceptionIfNameIsIllegal() {
+        Charset actual = Charsets.getSupportedCharset("spaces not allowed");
+        assertSame(Charset.defaultCharset(), actual);
+    }
+
+    @Test
+    public void testReturnRequestedCharsetIfSupported() {
+        Charset actual1 = Charsets.getSupportedCharset("UTF-8");
+        assertSame(Charset.forName("UTF-8"), actual1);
+
+        Charset actual2 = Charsets.getSupportedCharset("ISO-8859-1");
+        assertSame(Charset.forName("ISO-8859-1"), actual2);
+
+        Charset actual3 = Charsets.getSupportedCharset("KOI8-R");
+        assertSame(Charset.forName("KOI8-R"), actual3);
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/helpers/CharsetsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1482944&r1=1482943&r2=1482944&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Wed May 15 16:31:34 2013
@@ -22,6 +22,9 @@
   </properties>
   <body>
     <release version="2.0-beta7" date="2013-??-??" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-255" dev="rpopma" type="fix">
+        Multi-byte character strings are now assumed to be in the platform default encoding,
not UTF-8.
+      </action>
       <action issue="LOG4J2-254" dev="rgoers" type="fix">
         Mark OutputStream in OutputStreamManager as volatile. Mark header and footer as final.
       </action>



Mime
View raw message