Merge pull request #419 from LogosBible/bug6404
authorMarek Safar <marek.safar@gmail.com>
Mon, 6 Aug 2012 15:17:53 +0000 (08:17 -0700)
committerMarek Safar <marek.safar@gmail.com>
Mon, 6 Aug 2012 15:17:53 +0000 (08:17 -0700)
Bug #6404: System.Text.Encoder only throws ArgumentOutOfRangeException when appropriate

mcs/class/corlib/System.Text/Encoder.cs
mcs/class/corlib/Test/System.Text/EncoderTest.cs

index 683444b16bc577e0745ca91da1269cbdaae8a08e..9082efc24ffc13c35f92d63156fb4990cfdd3534 100644 (file)
@@ -133,11 +133,11 @@ public abstract class Encoder
                        throw new ArgumentNullException ("chars");
                if (bytes == null)
                        throw new ArgumentNullException ("bytes");
-               if (charIndex < 0 || chars.Length <= charIndex)
+               if (charIndex < 0)
                        throw new ArgumentOutOfRangeException ("charIndex");
                if (charCount < 0 || chars.Length < charIndex + charCount)
                        throw new ArgumentOutOfRangeException ("charCount");
-               if (byteIndex < 0 || bytes.Length <= byteIndex)
+               if (byteIndex < 0)
                        throw new ArgumentOutOfRangeException ("byteIndex");
                if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
                        throw new ArgumentOutOfRangeException ("byteCount");
index 3102e3838a00383ac936b3bb2a0a80ae76226f92..27a8d4eeb4b21022dc7098bd1b1234305d11ba41 100644 (file)
@@ -64,6 +64,22 @@ namespace MonoTests.System.Text
                        Assert.IsNotNull (encoder);
                }
 
+               [Test]
+               public void ConvertZeroCharacters ()
+               {
+                       int charsUsed, bytesUsed;
+                       bool completed;
+                       byte [] bytes = new byte [0];
+
+                       Encoding.UTF8.GetEncoder ().Convert (
+                               new char[0], 0, 0, bytes, 0, bytes.Length, true,
+                               out charsUsed, out bytesUsed, out completed);
+
+                       Assert.IsTrue (completed, "#1");
+                       Assert.AreEqual (0, charsUsed, "#2");
+                       Assert.AreEqual (0, bytesUsed, "#3");
+               }
+
                class CustomEncoding : Encoding {
 
                        public override int GetByteCount (char [] chars, int index, int count)