]> source.dussan.org Git - tigervnc.git/commitdiff
Don't violate RFB spec by sending UTF-8 141/head
authorBrian P. Hinz <bphinz@users.sf.net>
Sun, 1 Mar 2015 19:40:03 +0000 (14:40 -0500)
committerBrian P. Hinz <bphinz@users.sf.net>
Sun, 1 Mar 2015 19:40:03 +0000 (14:40 -0500)
Java viewer was violating the RFB specification by sending UTF-8 encoded clipboard text rather than ISO-8859-1.

java/com/tigervnc/rfb/CMsgWriter.java

index 3b226b166b048763787b53ae8e39451cd8303aa2..0d3dccf9facf40aab645694dd39bd1ee53e398de 100644 (file)
@@ -20,6 +20,8 @@
 
 package com.tigervnc.rfb;
 
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
 import com.tigervnc.rdr.*;
 
 abstract public class CMsgWriter {
@@ -155,12 +157,9 @@ abstract public class CMsgWriter {
     startMsg(MsgTypes.msgTypeClientCutText);
     os.pad(3);
     os.writeU32(len);
-    try {
-      byte[] utf8str = str.getBytes("UTF8");
-      os.writeBytes(utf8str, 0, len);
-    } catch(java.io.UnsupportedEncodingException e) {
-      e.printStackTrace();
-    }
+    Charset latin1 = Charset.forName("ISO-8859-1");
+    ByteBuffer bytes = latin1.encode(str);
+    os.writeBytes(bytes.array(), 0, len);
     endMsg();
   }