directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r662782 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/name/RdnParser.java main/java/org/apache/directory/shared/ldap/util/DNUtils.java test/java/org/apache/directory/shared/ldap/name/RdnTest.java
Date Tue, 03 Jun 2008 13:19:43 GMT
Author: elecharny
Date: Tue Jun  3 06:19:42 2008
New Revision: 662782

URL: http://svn.apache.org/viewvc?rev=662782&view=rev
Log:
Fix for DIRSERVER-1183

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?rev=662782&r1=662781&r2=662782&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
Tue Jun  3 06:19:42 2008
@@ -420,6 +420,7 @@
             pos.length = 0;
             pos.end = pos.start;
             int nbBytes = 0;
+            int length = 0;
 
             // <attributeValue> ::= '"' <quotechar-or-pair> '"'
             // <quotechar-or-pairs> ::= <quotechar> <quotechar-or-pairs>
| '\'
@@ -431,22 +432,40 @@
                     pos.end++;
                     int nbChars = 0;
 
-                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.start ) ) != DNUtils.PARSING_ERROR
)
+                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.end ) ) == DNUtils.PARSING_ERROR
)
                     {
-                        pos.end += nbChars;
+                        return null;
                     }
                     else
                     {
-                        return null;
+                        if ( nbChars == 1 )
+                        {
+                            buffer[currPos++] = bytes[pos.end];
+                        }
+                        else
+                        {
+                            byte b = StringTools.getHexValue( bytes[pos.end], bytes[pos.end
+ 1] );
+
+                            buffer[currPos++] = b;
+                        }
+                        
+                        pos.end += nbChars;
+                        length += nbChars;
                     }
                 }
                 else if ( ( nbBytes = DNUtils.isQuoteChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR
)
                 {
+                    for ( int i = 0; i < nbBytes; i++ )
+                    {
+                        buffer[currPos++] = bytes[pos.end + i];
+                    }
+                    
                     pos.end += nbBytes;
+                    length += nbBytes;
                 }
                 else
                 {
-                    pos.length = pos.end - pos.start;
+                    //pos.length = pos.end - pos.start;
                     break;
                 }
             }
@@ -454,7 +473,8 @@
             if ( StringTools.isCharASCII( bytes, pos.end, '"' ) )
             {
                 pos.end++;
-                return StringTools.utf8ToString( bytes, pos.start, pos.length );
+                return StringTools.utf8ToString( buffer, length );
+                //return StringTools.utf8ToString( bytes, pos.start, pos.length );
             }
             else
             {
@@ -464,7 +484,6 @@
         else
         {
             int escapedSpace = -1;
-            boolean hasPairChar = false;
 
             while ( true )
             {
@@ -474,6 +493,7 @@
                     pos.end++;
 
                     int nbChars = 0;
+                    
                     if ( ( nbChars = DNUtils.countPairChar( bytes, pos.end ) ) == DNUtils.PARSING_ERROR
)
                     {
                         return null;
@@ -486,11 +506,6 @@
                         }
                         else
                         {
-                            if ( !hasPairChar )
-                            {
-                                hasPairChar = true;
-                            }
-
                             byte b = StringTools.getHexValue( bytes[pos.end], bytes[pos.end
+ 1] );
 
                             buffer[currPos++] = b;
@@ -647,7 +662,7 @@
                     pos.end++;
                     int nbChars = 0;
 
-                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.start ) ) != DNUtils.PARSING_ERROR
)
+                    if ( ( nbChars = DNUtils.countPairChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR
)
                     {
                         pos.end += nbChars;
                     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java?rev=662782&r1=662781&r2=662782&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
Tue Jun  3 06:19:42 2008
@@ -19,14 +19,12 @@
  */
 package org.apache.directory.shared.ldap.util;
 
-import org.apache.directory.shared.ldap.util.Position;
-import org.apache.directory.shared.ldap.util.StringTools;
-
 
 /**
  * Utility class used by the LdapDN Parser.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
  */
 public class DNUtils
 {
@@ -123,28 +121,52 @@
         };
 
     /**
-     * ' ' | '"' | '#' | '+' | ',' | [0-9] | ';' | '<' | '=' | '>' | [A-F] | '\' |
-     * [a-f] 0x22 | 0x23 | 0x2B | 0x2C | [0x30-0x39] | 0x3B | 0x3C | 0x3D | 0x3E |
+     * ' ' | '"' | '#' | '+' | ',' | [0-9] | ';' | '<' | '=' | '>' | [A-F] | '\' |
[a-f]
+     * 0x22 | 0x23 | 0x2B | 0x2C | [0x30-0x39] | 0x3B | 0x3C | 0x3D | 0x3E |
      * [0x41-0x46] | 0x5C | [0x61-0x66]
      */
     private static final boolean[] PAIR_CHAR =
         { 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            true,  false, true,  true,  false, false, false, false, 
-            false, false, false, true,  true,  false, false, false, 
-            true,  true,  true,  true,  true,  true,  true,  true, 
-            true,  true,  false, true,  true,  true,  true,  false, 
-            false, true,  true,  true,  true,  true,  true,  false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, true,  false, false, false, 
-            false, true,  true,  true,  true,  true,  true,  false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false, 
-            false, false, false, false, false, false, false, false 
+            false, false, false, false, false, false, false, false, // 00 -> 07
+            false, false, false, false, false, false, false, false, // 08 -> 0F
+            false, false, false, false, false, false, false, false, // 10 -> 17
+            false, false, false, false, false, false, false, false, // 18 -> 1F
+            true,  false, true,  true,  false, false, false, false, // 20 -> 27 ( ' ',
'"', '#' )
+            false, false, false, true,  true,  false, false, false, // 28 -> 2F ( '+',
',' )
+            true,  true,  true,  true,  true,  true,  true,  true,  // 30 -> 37 ( '0'..'7'
)
+            true,  true,  false, true,  true,  true,  true,  false, // 38 -> 3F ( '8',
'9', ';', '<', '=', '>' ) 
+            false, true,  true,  true,  true,  true,  true,  false, // 40 -> 47 ( 'A',
'B', 'C', 'D', 'E', 'F' )
+            false, false, false, false, false, false, false, false, // 48 -> 4F
+            false, false, false, false, false, false, false, false, // 50 -> 57
+            false, false, false, false, true,  false, false, false, // 58 -> 5F ( '\'
)
+            false, true,  true,  true,  true,  true,  true,  false, // 60 -> 67 ( 'a',
'b', 'c', 'd', 'e', 'f' )
+            false, false, false, false, false, false, false, false, // 68 -> 6F
+            false, false, false, false, false, false, false, false, // 70 -> 77
+            false, false, false, false, false, false, false, false  // 78 -> 7F
+        };
+
+    /**
+     * ' ' | '"' | '#' | '+' | ',' | ';' | '<' | '=' | '>' | '\' |
+     * 0x22 | 0x23 | 0x2B | 0x2C | 0x3B | 0x3C | 0x3D | 0x3E | 0x5C
+     */
+    private static final boolean[] PAIR_CHAR_ONLY =
+        { 
+            false, false, false, false, false, false, false, false, // 00 -> 07
+            false, false, false, false, false, false, false, false, // 08 -> 0F
+            false, false, false, false, false, false, false, false, // 10 -> 17
+            false, false, false, false, false, false, false, false, // 18 -> 1F
+            true,  false, true,  true,  false, false, false, false, // 20 -> 27 ( ' ',
'"', '#' )
+            false, false, false, true,  true,  false, false, false, // 28 -> 2F ( '+',
',' )
+            false, false, false, false, false, false, false, false, // 30 -> 37
+            false, false, false, true,  true,  true,  true,  false, // 38 -> 3F ( ';',
'<', '=', '>' ) 
+            false, false, false, false, false, false, false, false, // 40 -> 47
+            false, false, false, false, false, false, false, false, // 48 -> 4F
+            false, false, false, false, false, false, false, false, // 50 -> 57
+            false, false, false, false, true,  false, false, false, // 58 -> 5F ( '\'
)
+            false, false, false, false, false, false, false, false, // 60 -> 67
+            false, false, false, false, false, false, false, false, // 68 -> 6F
+            false, false, false, false, false, false, false, false, // 70 -> 77
+            false, false, false, false, false, false, false, false  // 78 -> 7F
         };
 
     /**
@@ -202,7 +224,7 @@
         {
             byte c = bytes[index];
 
-            if ( ( ( c | 0x7F ) != 0x7F ) || ( SAFE_INIT_CHAR[c] == false ) )
+            if ( ( ( c | 0x7F ) != 0x7F ) || ( !SAFE_INIT_CHAR[c] ) )
             {
                 return -1;
             }
@@ -213,7 +235,7 @@
             {
                 c = bytes[index];
 
-                if ( ( ( c | 0x7F ) != 0x7F ) || ( SAFE_CHAR[c] == false ) )
+                if ( ( ( c | 0x7F ) != 0x7F ) || ( !SAFE_CHAR[c] ) )
                 {
                     break;
                 }
@@ -244,13 +266,13 @@
         {
             byte b = bytes[index++];
 
-            if ( StringTools.isAlpha( b ) == false )
+            if ( StringTools.isAlpha( b ) )
             {
-                return -1;
+                return index-1;
             }
             else
             {
-                return index;
+                return -1;
             }
         }
     }
@@ -274,19 +296,23 @@
         {
             byte c = bytes[index];
 
-            if ( ( ( c | 0x7F ) != 0x7F )  || ( PAIR_CHAR[c] == false ) )
+            if ( ( ( c | 0x7F ) != 0x7F )  || ( !PAIR_CHAR[c] ) )
             {
                 return false;
             }
             else
             {
-                if ( StringTools.isHex( bytes, index++ ) )
+                if ( PAIR_CHAR_ONLY[c] )
+                {
+                    return true;
+                }
+                else if ( StringTools.isHex( bytes, index++ ) )
                 {
                     return StringTools.isHex( bytes, index );
                 }
                 else
                 {
-                    return true;
+                    return false;
                 }
             }
         }
@@ -320,19 +346,23 @@
         {
             byte c = bytes[index];
 
-            if ( ( ( c | 0x7F ) != 0x7F )  || ( PAIR_CHAR[c] == false ) )
+            if ( ( ( c | 0x7F ) != 0x7F )  || ( !PAIR_CHAR[c] ) )
             {
                 return PARSING_ERROR;
             }
             else
             {
-                if ( StringTools.isHex( bytes, index++ ) )
+                if ( PAIR_CHAR_ONLY[c] )
+                {
+                    return 1;
+                }
+                else if ( StringTools.isHex( bytes, index++ ) )
                 {
                     return StringTools.isHex( bytes, index ) ? 2 : PARSING_ERROR;
                 }
                 else
                 {
-                    return 1;
+                    return PARSING_ERROR;
                 }
             }
         }
@@ -532,7 +562,7 @@
         {
             byte c = bytes[index];
 
-            if ( ( ( c | 0x7F ) != 0x7F )  || ( BASE64_CHAR[c] == false ) )
+            if ( ( ( c | 0x7F ) != 0x7F )  || ( !BASE64_CHAR[c] ) )
             {
                 return -1;
             }
@@ -543,7 +573,7 @@
             {
                 c = bytes[index];
 
-                if ( ( ( c | 0x7F ) != 0x7F )  || ( BASE64_CHAR[c] == false ) )
+                if ( ( ( c | 0x7F ) != 0x7F )  || ( !BASE64_CHAR[c] ) )
                 {
                     break;
                 }

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java?rev=662782&r1=662781&r2=662782&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
Tue Jun  3 06:19:42 2008
@@ -1257,4 +1257,22 @@
         assertEquals( "a=", new Rdn( "a=" ).toString() );
     }
 
+    /**
+     * test an RDN with escaped comma
+     */
+    @Test
+    public void testRdnWithEscapedComa() throws InvalidNameException
+    {
+        assertTrue( RdnParser.isValid( "a=b\\,c" ) );
+        assertEquals( "a=b\\,c", new Rdn( "a=b\\,c" ).toString() );
+
+        assertTrue( RdnParser.isValid( "a=\"b,c\"" ) );
+        assertEquals( "a=b\\,c", new Rdn( "a=\"b,c\"" ).toString() );
+        assertEquals( "a=\"b,c\"", new Rdn( "a=\"b,c\"" ).getUpName() );
+
+        assertTrue( RdnParser.isValid( "a=\"b\\,c\"" ) );
+        Rdn rdn = new Rdn( "a=\"b\\,c\"" );
+        assertEquals( "a=\"b\\,c\"", new Rdn( "a=\"b\\,c\"" ).getUpName() );
+        assertEquals( "a=b\\,c", new Rdn( "a=\"b\\,c\"" ).toString() );
+    }
 }



Mime
View raw message