directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r595078 - in /directory/shared/branches/bigbang/ldap/src: main/java/org/apache/directory/shared/ldap/name/Rdn.java main/java/org/apache/directory/shared/ldap/name/RdnParser.java test/java/org/apache/directory/shared/ldap/name/RdnTest.java
Date Wed, 14 Nov 2007 21:47:13 GMT
Author: elecharny
Date: Wed Nov 14 13:47:05 2007
New Revision: 595078

URL: http://svn.apache.org/viewvc?rev=595078&view=rev
Log:
Fixed some bugs with escaped spaces in the middle of a RDN value, and another one with a truncated
value due to an escaped space. Added Stefan Seelmann tests.

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=595078&r1=595077&r2=595078&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
Wed Nov 14 13:47:05 2007
@@ -1125,8 +1125,32 @@
            switch ( chars[i] )
            {
                case ' ':
-               case '"':
+                   if ( ( i > 0 ) && ( i < chars.length - 1 ) )
+                   {
+                       newChars[pos++] = chars[i];
+                   }
+                   else
+                   {
+                       newChars[pos++] = '\\';
+                       newChars[pos++] = chars[i];
+                   }
+                   
+                   break;
+                   
                case '#':
+                   if ( i != 0 )
+                   {
+                       newChars[pos++] = chars[i];
+                   }
+                   else
+                   {
+                       newChars[pos++] = '\\';
+                       newChars[pos++] = chars[i];
+                   }
+                   
+                   break;
+                   
+               case '"':
                case '+':
                case ',':
                case ';':

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?rev=595078&r1=595077&r2=595078&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
Wed Nov 14 13:47:05 2007
@@ -508,6 +508,12 @@
                     // <stringchar> <pairs-or-strings>
                     if ( ( nbChars = DNUtils.isStringChar( bytes, pos.end ) ) != DNUtils.PARSING_ERROR
)
                     {
+                        // If the char is not a space, we have to switch off the escapedSpace
flag
+                        if ( ( escapedSpace != -1 ) && ! StringTools.isCharASCII(
bytes, pos.end, ' ' ) )
+                        {
+                            escapedSpace = -1;
+                        }
+                        
                         // A special case : if we have some spaces before the
                         // '+' character,
                         // we MUST skip them.

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java?rev=595078&r1=595077&r2=595078&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
Wed Nov 14 13:47:05 2007
@@ -488,7 +488,7 @@
    {
        String res = Rdn.escapeValue( StringTools.getBytesUtf8( "\\#,+;<>=\" " ) );
 
-       Assert.assertEquals( "\\\\\\#\\,\\+\\;\\<\\>\\=\\\"\\ ", res );
+       Assert.assertEquals( "\\\\#\\,\\+\\;\\<\\>\\=\\\"\\ ", res );
    }
 
 
@@ -506,7 +506,7 @@
        String res = Rdn.escapeValue( new byte[]
            { '\\', 0x00, '-', '+', '#', 0x7F, '-' } );
 
-       Assert.assertEquals( "\\\\\\00-\\+\\#\\7F-", res );
+       Assert.assertEquals( "\\\\\\00-\\+#\\7F-", res );
    }
 
     public void testDIRSERVER_703() throws InvalidNameException 
@@ -548,4 +548,68 @@
         assertFalse( iterator.hasNext() );
     }
 
+
+    public void testRdnWithSpaces() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( "cn=a\\ b\\ c" );
+        assertEquals( "cn=a b c", rdn.toString() );
+    }
+
+    public void testEscapedSpaceInValue() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( "cn=a b c" );
+        Rdn rdn2 = new Rdn( "cn=a\\ b\\ c" );
+        assertEquals( "cn=a b c", rdn1.toString() );
+        assertEquals( "cn=a b c", rdn2.toString() );
+        assertTrue( rdn1.equals( rdn2 ) );
+
+        Rdn rdn3 = new Rdn( "cn=\\ a b c\\ " );
+        Rdn rdn4 = new Rdn( "cn=\\ a\\ b\\ c\\ " );
+        assertEquals( "cn=\\ a b c\\ ", rdn3.toString() );
+        assertEquals( "cn=\\ a b c\\ ", rdn4.toString() );
+        assertTrue( rdn3.equals( rdn4 ) );
+    }
+
+
+    public void testEscapedHashInValue() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( "cn=a#b#c" );
+        Rdn rdn2 = new Rdn( "cn=a\\#b\\#c" );
+        assertEquals( "cn=a#b#c", rdn1.toString() );
+        assertEquals( "cn=a#b#c", rdn2.toString() );
+        assertTrue( rdn1.equals( rdn2 ) );
+
+        Rdn rdn3 = new Rdn( "cn=\\#a#b#c\\#" );
+        Rdn rdn4 = new Rdn( "cn=\\#a\\#b\\#c\\#" );
+        assertEquals( "cn=\\#a#b#c#", rdn3.toString() );
+        assertEquals( "cn=\\#a#b#c#", rdn4.toString() );
+        assertTrue( rdn3.equals( rdn4 ) );
+    }
+
+
+    public void testEscapedAttributeValue() throws InvalidNameException
+    {
+        // space doesn't need to be escaped in the middle of a string
+        assertEquals( "a b", Rdn.escapeValue( "a b" ) );
+        assertEquals( "a b c", Rdn.escapeValue( "a b c" ) );
+        assertEquals( "a b c d", Rdn.escapeValue( "a b c d" ) );
+
+        // space must be escaped at the beginning and the end of a string
+        assertEquals( "\\ a b", Rdn.escapeValue( " a b" ) );
+        assertEquals( "a b\\ ", Rdn.escapeValue( "a b " ) );
+        assertEquals( "\\ a b\\ ", Rdn.escapeValue( " a b " ) );
+        assertEquals( "\\  a  b \\ ", Rdn.escapeValue( "  a  b  " ) );
+        
+        // hash doesn't need to be escaped in the middle and the end of a string
+        assertEquals( "a#b", Rdn.escapeValue( "a#b" ) );
+        assertEquals( "a#b#", Rdn.escapeValue( "a#b#" ) );
+        assertEquals( "a#b#c", Rdn.escapeValue( "a#b#c" ) );
+        assertEquals( "a#b#c#", Rdn.escapeValue( "a#b#c#" ) );
+        assertEquals( "a#b#c#d", Rdn.escapeValue( "a#b#c#d" ) );
+        assertEquals( "a#b#c#d#", Rdn.escapeValue( "a#b#c#d#" ) );
+        
+        // hash must be escaped at the beginning of a string
+        assertEquals( "\\#a#b", Rdn.escapeValue( "#a#b" ) );
+        assertEquals( "\\##a#b", Rdn.escapeValue( "##a#b" ) );
+    }
 }



Mime
View raw message