directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r558863 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
Date Mon, 23 Jul 2007 21:17:58 GMT
Author: seelmann
Date: Mon Jul 23 14:17:57 2007
New Revision: 558863

URL: http://svn.apache.org/viewvc?view=rev&rev=558863
Log:
DIRSERVER-1005: Forced UTF-8 encoding

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?view=diff&rev=558863&r1=558862&r2=558863
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
Mon Jul 23 14:17:57 2007
@@ -19,6 +19,8 @@
  */
 package org.apache.directory.shared.ldap.ldif;
 
+import java.io.UnsupportedEncodingException;
+
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
@@ -168,9 +170,18 @@
             	String str = (String) value;
             	if ( !LdifUtils.isLDIFSafe( str ) )
             	{
-            		char[] encoded = Base64.encode( ( ( String ) value ).getBytes() );
-            		
-            		lineBuffer.append( ":: " + new String( encoded ) );
+            		char[] encoded;
+                    try
+                    {
+                        // force encoding using UTF-8 charset, as required in RFC2849 note
7
+                        encoded = Base64.encode( ( ( String ) value ).getBytes( "UTF-8" )
);
+                    }
+                    catch ( UnsupportedEncodingException e )
+                    {
+                        encoded = Base64.encode( ( ( String ) value ).getBytes() );
+                    }
+
+                    lineBuffer.append( ":: " + new String( encoded ) );
             	}
             	else
             	{

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java?view=diff&rev=558863&r1=558862&r2=558863
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
Mon Jul 23 14:17:57 2007
@@ -19,6 +19,10 @@
  */
 package org.apache.directory.shared.ldap.ldif;
 
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+
 import junit.framework.TestCase;
 
 public class LdifUtilsTest extends TestCase
@@ -224,5 +228,18 @@
         assertEquals( "abcde\n fghi\n jklm\n n", LdifUtils.stripLineToNChars( "abcdefghijklmn",
5 ) );
         assertEquals( "abcde\n fghi\n jklm\n no", LdifUtils.stripLineToNChars( "abcdefghijklmno",
5 ) );
         assertEquals( "abcde\n fghi\n jklm\n nop", LdifUtils.stripLineToNChars( "abcdefghijklmnop",
5 ) );
+    }
+    
+    
+    /**
+     * Tests that unsave characters are encoded using UTF-8 charset. 
+     * 
+     * @throws NamingException
+     */
+    public void testConvertToLdifEncoding() throws NamingException
+    {
+        Attributes attributes = new BasicAttributes( "cn", "Saarbr\u00FCcken" );
+        String ldif = LdifUtils.convertToLdif( attributes );
+        assertEquals( "cn:: U2FhcmJyw7xja2Vu\n", ldif );
     }
 }



Mime
View raw message