You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2009/10/09 12:28:54 UTC

svn commit: r823506 - in /felix/trunk/configadmin/src: main/java/org/apache/felix/cm/impl/CaseInsensitiveDictionary.java test/java/org/apache/felix/cm/impl/CaseInsensitiveDictionaryTest.java

Author: fmeschbe
Date: Fri Oct  9 10:28:53 2009
New Revision: 823506

URL: http://svn.apache.org/viewvc?rev=823506&view=rev
Log:
FELIX-1727 fixed key validation allowing leading dots and throwing on
empty keys (not allowed as per the syntax)

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=823506&r1=823505&r2=823506&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 Fri Oct  9 10:28:53 2009
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -124,7 +124,7 @@
         {
             tmp.putAll( props.internalMap );
         }
-        
+
         internalMap = tmp;
         originalKeys = new Hashtable( props.originalKeys );
     }
@@ -132,7 +132,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.util.Dictionary#elements()
      */
     public Enumeration elements()
@@ -143,7 +143,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.util.Dictionary#get(java.lang.Object)
      */
     public Object get( Object key )
@@ -160,7 +160,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.util.Dictionary#isEmpty()
      */
     public boolean isEmpty()
@@ -171,7 +171,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.util.Dictionary#keys()
      */
     public Enumeration keys()
@@ -182,7 +182,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)
      */
     public Object put( Object key, Object value )
@@ -203,7 +203,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.util.Dictionary#remove(java.lang.Object)
      */
     public Object remove( Object key )
@@ -221,7 +221,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.util.Dictionary#size()
      */
     public int size()
@@ -235,7 +235,7 @@
     /**
      * Ensures the <code>key</code> complies with the <em>symbolic-name</em>
      * production of the OSGi core specification (1.3.2):
-     * 
+     *
      * <pre>
      * symbolic-name :: = token('.'token)*
      * digit    ::= [0..9]
@@ -243,10 +243,10 @@
      * alphanum ::= alpha | digit
      * token    ::= ( alphanum | ’_’ | ’-’ )+
      * </pre>
-     * 
+     *
      * If the key does not comply an <code>IllegalArgumentException</code> is
      * thrown.
-     * 
+     *
      * @param key
      *            The configuration property key to check.
      * @throws IllegalArgumentException
@@ -254,17 +254,27 @@
      */
     static void checkKey( Object keyObject )
     {
+        // check for wrong type or null key
         if ( !( keyObject instanceof String ) )
         {
             throw new IllegalArgumentException( "Key [" + keyObject + "] must be a String" );
         }
 
         String key = ( String ) keyObject;
-        if ( key.startsWith( "." ) || key.endsWith( "." ) )
+
+        // check for empty string
+        if ( key.length() == 0 )
+        {
+            throw new IllegalArgumentException( "Key [" + key + "] must not be an empty string" );
+        }
+
+        // check for trailing dot
+        if ( key.endsWith( "." ) )
         {
-            throw new IllegalArgumentException( "Key [" + key + "] must not start or end with a dot" );
+            throw new IllegalArgumentException( "Key [" + key + "] must not end with a dot" );
         }
 
+        // check for legal characters and non-consecutive dots
         int lastDot = Integer.MIN_VALUE;
         for ( int i = 0; i < key.length(); i++ )
         {

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=823506&r1=823505&r2=823506&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 Fri Oct  9 10:28:53 2009
@@ -211,7 +211,7 @@
     public void testKeyDots()
     {
         testFailingKey( "." );
-        testFailingKey( ".a.b.c" );
+        CaseInsensitiveDictionary.checkKey( ".a.b.c" );
         testFailingKey( "a.b.c." );
         testFailingKey( ".a.b.c." );
         testFailingKey( "a..b" );
@@ -220,6 +220,8 @@
 
     public void testKeyIllegalCharacters()
     {
+        testFailingKey( null );
+        testFailingKey( "" );
         testFailingKey( " " );
         testFailingKey( "§" );
         testFailingKey( "${yikes}" );