directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r768569 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/util/ test/java/org/apache/directory/shared/ldap/name/ test/java/org/apache/directory/shared/ldap/util/
Date Sat, 25 Apr 2009 18:11:13 GMT
Author: seelmann
Date: Sat Apr 25 18:11:12 2009
New Revision: 768569

URL: http://svn.apache.org/viewvc?rev=768569&view=rev
Log:
Fixed a corner case: the sequence ESC ESC HEX HEX was not handled correctly by StringTools.decodeEscapedHex()

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=768569&r1=768568&r2=768569&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Sat Apr 25 18:11:12 2009
@@ -3405,7 +3405,7 @@
         {
             char c = str.charAt( ii );
             
-            if ( c == '\\' )
+            if ( !escaped && c == '\\' )
             {
                 // we have the start of a hex escape sequence
                 if ( isHex( str, ii+1 ) && isHex ( str, ii+2 ) )
@@ -3417,7 +3417,7 @@
                     escaped = false;
                     continue;
                 }
-                else if ( !escaped )
+                else
                 {
                     // It may be an escaped char ( ' ', '"', '#', '+', ',', ';', '<',
'=', '>', '\' )
                     escaped = true;

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java?rev=768569&r1=768568&r2=768569&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
Sat Apr 25 18:11:12 2009
@@ -394,6 +394,25 @@
 
 
     /**
+     * Normalize a DN with sequence ESC ESC HEX HEX (\\DC).
+     * This is a corner case for the parser and normalizer.
+     */
+    @Test
+    public void testNormalizeLdapDNEscEscHexHex() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "ou = AC\\\\DC" );
+        assertTrue( LdapDN.isValid( "ou = AC\\\\DC" ) );
+        assertEquals( "ou=AC\\\\DC", dn.toString() );
+        assertEquals( "ou = AC\\\\DC", dn.getUpName() );
+
+        // Check the normalization now
+        LdapDN ndn = dn.normalize( oidOids );
+        assertEquals( "ou = AC\\\\DC", ndn.getUpName() );
+        assertEquals( "2.5.4.11=ac\\\\dc", ndn.toString() );
+    }
+
+
+    /**
      * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java?rev=768569&r1=768568&r2=768569&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/StringToolsTest.java
Sat Apr 25 18:11:12 2009
@@ -52,6 +52,20 @@
         assertEquals( "Ferry", StringTools.decodeEscapedHex( "Fe\\72\\72\\79" ) );
         assertEquals( "Ferry", StringTools.decodeEscapedHex( "Fe\\72\\72y" ) );
         assertEquals( "Ferry", StringTools.decodeEscapedHex( "Fe\\72ry" ) );
+
+        assertEquals( "<DC", StringTools.decodeEscapedHex( "\\<DC" ) );
+        assertEquals( ">DC", StringTools.decodeEscapedHex( "\\>DC" ) );
+        assertEquals( "\"DC", StringTools.decodeEscapedHex( "\\\"DC" ) );
+        assertEquals( "+DC", StringTools.decodeEscapedHex( "\\+DC" ) );
+        assertEquals( ",DC", StringTools.decodeEscapedHex( "\\,DC" ) );
+        assertEquals( ";DC", StringTools.decodeEscapedHex( "\\;DC" ) );
+        assertEquals( "=DC", StringTools.decodeEscapedHex( "\\=DC" ) );
+        assertEquals( " DC", StringTools.decodeEscapedHex( "\\ DC" ) );
+        assertEquals( "#DC", StringTools.decodeEscapedHex( "\\#DC" ) );
+
+        // test a corner case: ESC ESC HEX HEX
+        assertEquals( "\\DC", StringTools.decodeEscapedHex( "\\5CDC" ) );
+        assertEquals( "\\DC", StringTools.decodeEscapedHex( "\\\\DC" ) );
     }
     
     @Test



Mime
View raw message