nmkhoa / unitt

Automatically exported from code.google.com/p/unitt
0 stars 0 forks source link

Null Bytes on the end of message #44

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. send utf-8 message to a websocket server (Tornado)
2. print the income message with %r to the console, you then can see that for 
each char that is sent a null byte(0x00) is being added

What is the expected output? What do you see instead?
The expected output is without the null bytes

What version of the product are you using? On what operating system?
0.9.3

Please provide any additional information below.
I have implamented a solution for this issue, but I'm sure that it can be 
improved,
on the WebSocketConnection.java file I Edited the code on line 791 as follow:
if ( throwsErrorOnInvalidUtf8() )
                {
                    CharsetEncoder encoder = utf8Charset.newEncoder();
                    ByteBuffer buffer = encoder.encode( CharBuffer.wrap( aData ) );
                    byte[] bytes = buffer.array();
                    int i;
                    for(i= 0; i < bytes.length; i++){
                        if (bytes[i] == 0)
                            break;
                    }
                    byte[] out = new byte[i+1];
                    out = Arrays.copyOfRange(bytes, 0, i);
                    return out;
                }

Original issue reported on code.google.com by d...@omniscience.co.il on 3 Jun 2012 at 1:57

GoogleCodeExporter commented 8 years ago
Because This function convertFromStringToBytes, is used in more then one place, 
my solution is causing problems.

a more complete solution is needed to solve this issue 

Original comment by d...@omniscience.co.il on 3 Jun 2012 at 2:02

GoogleCodeExporter commented 8 years ago
I will take a look at this. Be looking for a fix in the next week or two. I 
have to get the Java/Android client to a RC release as well.

Original comment by joshuadmorris@gmail.com on 11 Jun 2012 at 9:33

GoogleCodeExporter commented 8 years ago
Current version of source code still has a same problem.
                    CharsetEncoder encoder = utf8Charset.newEncoder();
                    ByteBuffer buffer = encoder.encode(CharBuffer.wrap(aData));
                    return buffer.array();

Why don't you use only just this implementation.
      aData.getBytes("UTF-8");

Could you tell me why?

Original comment by ashira11 on 8 Nov 2012 at 12:21