You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/09/19 17:22:16 UTC

svn commit: r290185 - /directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/tlv/Value.java

Author: elecharny
Date: Mon Sep 19 08:22:11 2005
New Revision: 290185

URL: http://svn.apache.org/viewcvs?rev=290185&view=rev
Log:
Fixed a potiential error in encode(ByteBuffer, String) : the 
String.getBytes() was called, using the defalut platform encoding 
instead of UTF-8.

Thanks to Jérôme baumgarten for the repport !

Modified:
    directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/tlv/Value.java

Modified: directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/tlv/Value.java
URL: http://svn.apache.org/viewcvs/directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/tlv/Value.java?rev=290185&r1=290184&r2=290185&view=diff
==============================================================================
--- directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/tlv/Value.java (original)
+++ directory/asn1/trunk/ber-new/src/java/main/org/apache/asn1new/ber/tlv/Value.java Mon Sep 19 08:22:11 2005
@@ -23,6 +23,7 @@
 import org.apache.asn1new.util.StringUtils;
 
 import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
@@ -236,10 +237,10 @@
     }
 
     /**
-     * Encode an String value 
+     * Encode a String value 
      * 
      * @param buffer The PDU in which the value will be put
-     * @param string The String to be encoded
+     * @param string The String to be encoded. It is supposed to be UTF-8 
      */
     public static void encode( ByteBuffer buffer, String string ) throws EncoderException
     {
@@ -251,7 +252,17 @@
         try 
         {
             buffer.put( UniversalTag.OCTET_STRING_TAG );
-            byte[] value = string.getBytes();
+            
+            byte[] value = null;
+            
+            try 
+            {
+            	value = string.getBytes("UTF-8");
+            } 
+            catch (UnsupportedEncodingException uee)
+            {
+            	throw new EncoderException("The Value encoding is not UTF-8");
+            }
             
             buffer.put( Length.getBytes( value.length ) );