felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1561599 - in /felix/trunk/configadmin/src: main/java/org/apache/felix/cm/impl/CaseInsensitiveDictionary.java test/java/org/apache/felix/cm/impl/CaseInsensitiveDictionaryTest.java
Date Mon, 27 Jan 2014 08:07:53 GMT
Author: fmeschbe
Date: Mon Jan 27 08:07:53 2014
New Revision: 1561599

URL: http://svn.apache.org/r1561599
Log:
FELIX-4408 Fix lower casing in special case locales (such as Turkish) where
  some characters have special case upper and lower case characters.
  (applied slightly modified patch by Tobias Bocanegra, thanks alot)

Modified:
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/CaseInsensitiveDictionary.java
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/CaseInsensitiveDictionaryTest.java

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/CaseInsensitiveDictionary.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/CaseInsensitiveDictionary.java?rev=1561599&r1=1561598&r2=1561599&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/CaseInsensitiveDictionary.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/CaseInsensitiveDictionary.java
Mon Jan 27 08:07:53 2014
@@ -27,6 +27,7 @@ import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Vector;
 
@@ -74,7 +75,7 @@ public class CaseInsensitiveDictionary e
                 checkKey( key );
 
                 // check uniqueness of key
-                String lowerCase = ( ( String ) key ).toLowerCase();
+                String lowerCase = toLowerCase( key );
                 if ( internalMap.containsKey( lowerCase ) )
                 {
                     throw new IllegalArgumentException( "Key [" + key + "] already present
in different case" );
@@ -156,8 +157,7 @@ public class CaseInsensitiveDictionary e
             throw new NullPointerException( "key" );
         }
 
-        String stringKey = String.valueOf( key ).toLowerCase();
-        return internalMap.get( stringKey );
+        return internalMap.get( toLowerCase( key ) );
     }
 
 
@@ -198,7 +198,7 @@ public class CaseInsensitiveDictionary e
         checkKey( key );
         value = checkValue( value );
 
-        String lowerCase = String.valueOf( key ).toLowerCase();
+        String lowerCase = toLowerCase( key );
         originalKeys.put( lowerCase, key );
         return internalMap.put( lowerCase, value );
     }
@@ -216,7 +216,7 @@ public class CaseInsensitiveDictionary e
             throw new NullPointerException( "key" );
         }
 
-        String lowerCase = String.valueOf( key ).toLowerCase();
+        String lowerCase = toLowerCase( key );
         originalKeys.remove( lowerCase );
         return internalMap.remove( lowerCase );
     }
@@ -273,6 +273,13 @@ public class CaseInsensitiveDictionary e
     }
 
 
+    static final String toLowerCase( Object keyObject )
+    {
+        final String key = ( String ) keyObject;
+        return key.toLowerCase( Locale.ENGLISH );
+    }
+
+
     static Object checkValue( Object value )
     {
         Class type;

Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/CaseInsensitiveDictionaryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/CaseInsensitiveDictionaryTest.java?rev=1561599&r1=1561598&r2=1561599&view=diff
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/CaseInsensitiveDictionaryTest.java
(original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/CaseInsensitiveDictionaryTest.java
Mon Jan 27 08:07:53 2014
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Vector;
 
 import junit.framework.TestCase;
@@ -31,6 +32,28 @@ import junit.framework.TestCase;
 public class CaseInsensitiveDictionaryTest extends TestCase
 {
 
+    public void testLocaleIndependence() {
+        Locale defaultLocal = Locale.getDefault();
+        CaseInsensitiveDictionary dict = new CaseInsensitiveDictionary();
+        dict.put("illegal", "value1");
+        dict.put("ILLEGAL", "value2");
+        assertEquals(dict.get("illegal"), "value2");
+        assertEquals(dict.get("ILLEGAL"), "value2");
+
+        // validate "i" conversion with Turkish default locale
+        Locale.setDefault(new Locale("tr", "" ,""));
+        try {
+            dict = new CaseInsensitiveDictionary();
+            dict.put("illegal", "value1");
+            dict.put("ILLEGAL", "value2");
+            assertEquals(dict.get("illegal"), "value2");
+            assertEquals(dict.get("ILLEGAL"), "value2");
+        } finally {
+            Locale.setDefault(defaultLocal);
+        }
+    }
+
+
     public void testCheckValueNull()
     {
         // null which must throw IllegalArgumentException



Mime
View raw message