forked from pool/mono-core
9024f9f81c
OBS-URL: https://build.opensuse.org/request/show/308124 OBS-URL: https://build.opensuse.org/package/show/Mono:Factory/mono-core?expand=0&rev=151
55 lines
1.9 KiB
Diff
55 lines
1.9 KiB
Diff
From ed1d3ec5260b613849b9af27c9dbcb6566c1637c Mon Sep 17 00:00:00 2001
|
|
From: Marek Safar <marek.safar@gmail.com>
|
|
Date: Wed, 20 May 2015 09:55:49 +0200
|
|
Subject: [PATCH] [corlib] BinaryReader with Unicode encoding needs to read
|
|
bytes in a pair. Fixes #30171
|
|
|
|
---
|
|
mcs/class/corlib/System.IO/BinaryReader.cs | 7 +++++++
|
|
mcs/class/corlib/Test/System.IO/BinaryReaderTest.cs | 14 ++++++++++++++
|
|
2 files changed, 21 insertions(+)
|
|
|
|
diff --git a/mcs/class/corlib/System.IO/BinaryReader.cs b/mcs/class/corlib/System.IO/BinaryReader.cs
|
|
index 73235c9..bbcd817 100644
|
|
--- a/mcs/class/corlib/System.IO/BinaryReader.cs
|
|
+++ b/mcs/class/corlib/System.IO/BinaryReader.cs
|
|
@@ -253,6 +253,13 @@ private int ReadCharBytes (char[] buffer, int index, int count, out int bytes_re
|
|
|
|
m_buffer [pos ++] = (byte)read_byte;
|
|
bytes_read ++;
|
|
+ if (m_encoding is UnicodeEncoding) {
|
|
+ CheckBuffer (pos + 1);
|
|
+ read_byte = m_stream.ReadByte();
|
|
+ if (read_byte != -1) {
|
|
+ m_buffer [pos++] = (byte)read_byte;
|
|
+ }
|
|
+ }
|
|
|
|
int n = m_encoding.GetChars (m_buffer, 0, pos, buffer, index + chars_read);
|
|
if (n > 0)
|
|
diff --git a/mcs/class/corlib/Test/System.IO/BinaryReaderTest.cs b/mcs/class/corlib/Test/System.IO/BinaryReaderTest.cs
|
|
index 852d690..ca4e3da 100644
|
|
--- a/mcs/class/corlib/Test/System.IO/BinaryReaderTest.cs
|
|
+++ b/mcs/class/corlib/Test/System.IO/BinaryReaderTest.cs
|
|
@@ -274,6 +274,20 @@ public void TestReadChar()
|
|
}
|
|
}
|
|
|
|
+ [Test]
|
|
+ public void TestReadUnicode ()
|
|
+ {
|
|
+ char testChar1 = 'H';
|
|
+ using (var stream = new MemoryStream())
|
|
+ using (var writer = new BinaryWriter(stream, Encoding.Unicode, true))
|
|
+ using (var reader = new BinaryReader(stream, Encoding.Unicode))
|
|
+ {
|
|
+ writer.Write(testChar1);
|
|
+ stream.Position = 0;
|
|
+ Assert.AreEqual ('H', reader.ReadChar ());
|
|
+ }
|
|
+ }
|
|
+
|
|
|
|
//-TODO: (TestRead[Type]*) Verify the ReadBoolean, ReadByte ....
|
|
// ReadBoolean, ReadByte, ReadChar, ReadInt32 Done
|