Procházet zdrojové kódy

2006-02-14 Atsushi Enomoto <[email protected]>

	* UTF8Encoding.cs : Fallback was indicating incorrect index.
	  Fixed bug #77550.

	* UTF8EncodingTest.cs : test for bug #77550.


svn path=/trunk/mcs/; revision=56848
Atsushi Eno před 20 roky
rodič
revize
ce4d8a502d

+ 5 - 0
mcs/class/corlib/System.Text/ChangeLog

@@ -1,3 +1,8 @@
+2006-02-14  Atsushi Enomoto  <[email protected]>
+
+	* UTF8Encoding.cs : Fallback was indicating incorrect index.
+	  Fixed bug #77550.
+
 2006-02-10  Atsushi Enomoto  <[email protected]>
 
 	* ASCIIEncoding.cs : (GetChars) reduced either one store or one jump

+ 3 - 5
mcs/class/corlib/System.Text/UTF8Encoding.cs

@@ -442,8 +442,6 @@ Char.IsLetterOrDigit (pair);
 	// Internal version of "GetCharCount" which can handle a rolling
 	// state between multiple calls to this method.
 #if NET_2_0
-	// Internal version of "GetCharCount" which can handle a rolling
-	// state between multiple calls to this method.
 	private static int InternalGetCharCount (
 		byte[] bytes, int index, int count, uint leftOverBits,
 		uint leftOverCount, object provider,
@@ -590,7 +588,7 @@ Char.IsLetterOrDigit (pair);
 			// We had left-over bytes that didn't make up
 			// a complete UTF-8 character sequence.
 #if NET_2_0
-			length += Fallback (provider, ref fallbackBuffer, bytes, index - 1);
+			length += Fallback (provider, ref fallbackBuffer, bytes, index);
 #else
 			if (throwOnInvalid)
 				throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
@@ -612,7 +610,7 @@ Char.IsLetterOrDigit (pair);
 			else
 				buffer = ((Decoder) provider).FallbackBuffer;
 		}
-		buffer.Fallback (bytes, index - 1);
+		buffer.Fallback (bytes, index);
 		return buffer.Remaining;
 	}
 
@@ -627,7 +625,7 @@ Char.IsLetterOrDigit (pair);
 			else
 				buffer = ((Decoder) provider).FallbackBuffer;
 		}
-		buffer.Fallback (bytes, byteIndex - 1);
+		buffer.Fallback (bytes, byteIndex);
 		while (buffer.Remaining > 0)
 			chars [charIndex++] = buffer.GetNextChar ();
 	}

+ 4 - 0
mcs/class/corlib/Test/System.Text/ChangeLog

@@ -1,3 +1,7 @@
+2006-02-14  Atsushi Enomoto  <[email protected]>
+
+	* UTF8EncodingTest.cs : test for bug #77550.
+
 2006-02-03  Atsushi Enomoto  <[email protected]>
 
 	* UTF8EncodingTest.cs : added test for insufficient bytes for

+ 19 - 0
mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs

@@ -19,6 +19,8 @@ using DecoderException = System.Text.DecoderFallbackException;
 using DecoderException = System.ArgumentException;
 #endif
 
+using AssertType = NUnit.Framework.Assert;
+
 namespace MonoTests.System.Text {
 
 	[TestFixture]
@@ -1046,5 +1048,22 @@ namespace MonoTests.System.Text {
 			} catch (ArgumentException) {
 			}
 		}
+
+#if NET_2_0
+		[Test] // bug #77550
+		public void DecoderFallbackSimple ()
+		{
+			UTF8Encoding e = new UTF8Encoding (false, false);
+			AssertType.AreEqual (0, e.GetDecoder ().GetCharCount (
+					new byte [] {(byte) 183}, 0, 1),
+					"#1");
+			AssertType.AreEqual (0, e.GetDecoder().GetChars (
+					new byte [] {(byte) 183}, 0, 1,
+					new char [100], 0),
+					"#2");
+			AssertType.AreEqual (0, e.GetString (new byte [] {(byte) 183}).Length,
+					"#3");
+		}
+#endif
 	}
 }