2012/12/25  <ma...@apache.org>:
> Author: markt
> Date: Mon Dec 24 21:07:01 2012
> New Revision: 1425680
>
> URL: http://svn.apache.org/viewvc?rev=1425680&view=rev
> Log:
> Text messages are always UTF8
> (Note that even with this fix Autobahn identifies a lot of UTF-8 handling 
> issues. The quick and dirty new String() approach needs a more robust 
> replacement.)
>
> Modified:
>     tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
>
> Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
> URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java?rev=1425680&r1=1425679&r2=1425680&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java (original)
> +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java Mon Dec 24 
> 21:07:01 2012
> @@ -18,6 +18,7 @@ package org.apache.tomcat.websocket;
>
>  import java.io.EOFException;
>  import java.io.IOException;
> +import java.io.UnsupportedEncodingException;
>  import java.nio.ByteBuffer;
>
>  import javax.servlet.ServletInputStream;
> @@ -282,8 +283,13 @@ public class WsFrame {
>      @SuppressWarnings("unchecked")
>      private void sendMessage(boolean last) {
>          if (textMessage) {
> -            String payload =
> -                    new String(messageBuffer.array(), 0, 
> messageBuffer.limit());
> +            String payload = null;
> +            try {
> +                payload = new String(messageBuffer.array(), 0,
> +                        messageBuffer.limit(), "UTF8");
> +            } catch (UnsupportedEncodingException e) {
> +                // All JVMs must support UTF8
> +            }
>              MessageHandler mh = wsSession.getTextMessageHandler();
>              if (mh != null) {
>                  if (mh instanceof MessageHandler.Async<?>) {
>

Looking at the current code, "new String()" call still remains in WsFrame.java
Starting with Line 270:

                if (controlBufferBinary.remaining() > 0) {
                    CoderResult cr = utf8DecoderControl.decode(
                            controlBufferBinary, controlBufferText, true);
                    if (cr.isError()) {
                        controlBufferBinary.clear();
                        controlBufferText.clear();
                        throw new WsIOException(new CloseReason(
                                CloseCodes.PROTOCOL_ERROR,
                                sm.getString("wsFrame.invalidUtf8Close")));
                    }
                    reason = new String(controlBufferBinary.array(),
                            controlBufferBinary.arrayOffset() +
                                    controlBufferBinary.position(),
                            controlBufferBinary.remaining(), "UTF8");
                }

Why use "new String(.., UTF8)" when there is
"utf8DecoderControl.decode(..)" call several lines above?

Isn't it supposed to use controlBufferText here ?

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to