Просмотр исходного кода

2009-10-09 Atsushi Enomoto <[email protected]>

	* ISO2022JP.cs : simply output wrong escape sequence bytes to the
	  output (like .NET does).

	* I18N.CJK.Test.cs : added test for iso-2022-jp wrong esc sequences.


svn path=/trunk/mcs/; revision=143819
Atsushi Eno 16 лет назад
Родитель
Сommit
daf04bd1a6

+ 5 - 0
mcs/class/I18N/CJK/ChangeLog

@@ -1,3 +1,8 @@
+2009-10-09  Atsushi Enomoto  <[email protected]>
+
+	* ISO2022JP.cs : simply output wrong escape sequence bytes to the
+	  output (like .NET does).
+
 2009-04-15  Atsushi Enomoto  <[email protected]>
 
 	* jis.table : regenerated. Fixed bug #491799.

+ 16 - 8
mcs/class/I18N/CJK/ISO2022JP.cs

@@ -438,8 +438,10 @@ namespace I18N.CJK
 						wide = true;
 					else if (bytes [i] == 0x28)
 						wide = false;
-					else
-						throw new ArgumentException ("Unexpected ISO-2022-JP escape sequence.");
+					else {
+						ret += 2;
+						continue;
+					}
 					i++;
 					if (bytes [i] == 0x42)
 						m = wide ? ISO2022JPMode.JISX0208 : ISO2022JPMode.ASCII;
@@ -448,7 +450,7 @@ namespace I18N.CJK
 					else if (bytes [i] == 0x49)
 						m = ISO2022JPMode.JISX0201;
 					else
-						throw new ArgumentException (String.Format ("Unexpected ISO-2022-JP escape sequence. Ended with 0x{0:X04}", bytes [i]));
+						ret += 3;
 				}
 			}
 			return ret;
@@ -457,7 +459,7 @@ namespace I18N.CJK
 		private int ToChar (int value)
 		{
 			value <<= 1;
-			return value + 1 >= convert.jisx0208ToUnicode.Length ?
+			return value + 1 >= convert.jisx0208ToUnicode.Length  || value < 0 ?
 				-1 :
 				((int) (convert.jisx0208ToUnicode [value])) |
 					(((int) (convert.jisx0208ToUnicode [value + 1])) << 8);
@@ -523,8 +525,11 @@ namespace I18N.CJK
 						wide = true;
 					else if (bytes [i] == 0x28)
 						wide = false;
-					else
-						throw new ArgumentException ("Unexpected ISO-2022-JP escape sequence.");
+					else {
+						chars [charIndex++] = '\x1B';
+						chars [charIndex++] = (char) bytes [i];
+						continue;
+					}
 					i++;
 					if (bytes [i] == 0x42)
 						m = wide ? ISO2022JPMode.JISX0208 : ISO2022JPMode.ASCII;
@@ -532,8 +537,11 @@ namespace I18N.CJK
 						m = ISO2022JPMode.ASCII;
 					else if (bytes [i] == 0x49)
 						m = ISO2022JPMode.JISX0201;
-					else
-						throw new ArgumentException (String.Format ("Unexpected ISO-2022-JP escape sequence. Ended with 0x{0:X04}", bytes [i]));
+					else {
+						chars [charIndex++] = '\x1B';
+						chars [charIndex++] = (char) bytes [i - 1];
+						chars [charIndex++] = (char) bytes [i];
+					}
 				}
 			}
 

+ 4 - 0
mcs/class/I18N/CJK/Test/ChangeLog

@@ -1,3 +1,7 @@
+2009-10-09  Atsushi Enomoto  <[email protected]>
+
+	* I18N.CJK.Test.cs : added test for iso-2022-jp wrong esc sequences.
+
 2009-04-15  Atsushi Enomoto  <[email protected]>
 
 	* I18N.CJK.Test.cs : added test for bug #491799.

+ 20 - 0
mcs/class/I18N/CJK/Test/I18N.CJK.Test.cs

@@ -192,6 +192,26 @@ namespace MonoTests.I18N.CJK
 			AssertDecode ("Test/texts/japanese-utf8.txt", "Test/texts/japanese-50222.txt", 50222);
 		}
 
+		[Test]
+		public void CP50220BrokenESC ()
+		{
+			Assert.AreEqual ("\u001B$0", Encoding.GetEncoding (50220).GetString (new byte [] {0x1B, 0x24, 0x30}), "#1");
+		}
+
+		[Test]
+		public void CP50220BrokenESC2 ()
+		{
+			// it does not really invoke fallback ...
+			Assert.AreEqual ("\u001B$0", Encoding.GetEncoding (50220, new EncoderReplacementFallback (), new DecoderReplacementFallback ("")).GetString (new byte [] {0x1B, 0x24, 0x30}), "#1");
+		}
+
+		[Test]
+		public void CP50220BrokenESC3 ()
+		{
+			// neither ...
+			Assert.AreEqual ("\u001B$0", Encoding.GetEncoding (50220, new EncoderExceptionFallback (), new DecoderExceptionFallback ()).GetString (new byte [] {0x1B, 0x24, 0x30}), "#2");
+		}
+
 		[Test]
 #if !NET_2_0
 		[Category ("NotDotNet")] // MS bug