2010-01-23 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Sun, 24 Jan 2010 04:07:35 +0000 (04:07 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Sun, 24 Jan 2010 04:07:35 +0000 (04:07 -0000)
* StreamReader.cs: When detecting the encoding we usually check the
four first bytes looking for either UTF32 or UTF8 BOM, since they share
the first two bytes, but if we happen to have less than 4 bytes at
detection time, just check for Unicode and use it as the current
encoding - this is exactly what .Net does, and it is specially visible
with NetworkStream.
Fixes #534137.

svn path=/trunk/mcs/; revision=150090

mcs/class/corlib/System.IO/ChangeLog
mcs/class/corlib/System.IO/StreamReader.cs

index 32f674f0b6768f9f6b52e263945bb7f9c22cd6ee..dd16a1877b1d52d1c32d94bd93dd875af4bcf807 100644 (file)
@@ -1,3 +1,13 @@
+2010-01-23  Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+       * StreamReader.cs: When detecting the encoding we usually check the
+       four first bytes looking for either UTF32 or UTF8 BOM, since they share
+       the first two bytes, but if we happen to have less than 4 bytes at
+       detection time, just check for Unicode and use it as the current
+       encoding - this is exactly what .Net does, and it is specially visible
+       with NetworkStream.
+       Fixes #534137.
+
 2010-01-19  Alan McGovern  <amcgovern@novell.com>
        * BufferedStream.cs: Patch by Tom Philpot to optimise ReadByte and
        WriteByte significantly by making them fulfill their request by
index 438f0b97ecc36e587a1f7ddd01847f654ff439d3..9e5f558585cc855ee4d9b226d871e4088cc6be2f 100644 (file)
@@ -311,6 +311,11 @@ namespace System.IO {
                                        this.encoding = Encoding.BigEndianUnicode;
                                        return 2;
                                }
+                               if (input_buffer [0] == 0xff && input_buffer [1] == 0xfe && count < 4) {
+                                       // If we don't have enough bytes we can't check for UTF32, so use Unicode
+                                       this.encoding = Encoding.Unicode;
+                                       return 2;
+                               }
 
                                if (count < 3)
                                        return 0;