Le 9/17/12 2:50 PM, Emmanuel Lécharny a écrit :
Le 9/17/12 2:21 PM, Niklas Gustavsson a écrit :
Hey
yo,

When upgrading to MINA 2.0.5 in FtpServer, I noticed one of the
FtpServer unit tests breaking. Turns out it's due to a change
(r1374997) in MINA 2.0.5 TextLineDecoder which no longer will throw an
exception on some input which is not valid for the charset. For
example, this test will throw an exception on MINA 2.0.4, but will
pass and output a broken String on 2.0.5.

Seems like a regression.

The modification in MINA 2.0.5 was wuite minor, and was expecting to fix a problme with lines containing a 0x00 char (which is valid in Strings) which was considered -wrongly - as a line terminator.

I' investigating the impact on FtpServer test atm.



I have a fix for the issue, but it will take a bit of time to get a new MINA release cut.

Basically, I don't use anymore 'new String()' directly, as it swallows bad chars and ignore them (they will be replaced by ? in the resulting String).

The patch is :

Index: mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java
===================================================================
--- mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java (revision 1375418) +++ mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java (working copy)
@@ -19,6 +19,8 @@
  */
 package org.apache.mina.filter.codec.textline;

+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
@@ -269,7 +271,11 @@
                     try {
                         byte[] data = new byte[buf.limit()];
                         buf.get(data);
- writeText(session, new String(data, ctx.getDecoder().charset()), out);
+                        CharsetDecoder decoder = ctx.getDecoder();
+
+ CharBuffer buffer = decoder.decode(ByteBuffer.wrap(data));
+                        String str = new String(buffer.array());
+                        writeText(session, str, out);
                     } finally {
                         buf.clear();
                     }


--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Reply via email to