[corlib] Unicode numbers are not considers valid in number parsing. Fixes #17628
authorMarek Safar <marek.safar@gmail.com>
Fri, 14 Feb 2014 16:36:26 +0000 (17:36 +0100)
committerMarek Safar <marek.safar@gmail.com>
Fri, 14 Feb 2014 16:36:26 +0000 (17:36 +0100)
mcs/class/corlib/System/Int32.cs
mcs/class/corlib/Test/System/Int32Test.cs
mcs/class/corlib/Test/System/Int64Test.cs
mcs/class/corlib/Test/System/UInt32Test.cs
mcs/class/corlib/Test/System/UInt64Test.cs

index 756e014785eac0e8a5691544d315e315312f52bf..02b4481b18b5ae18de48c2ae6acb76e347ef810f 100644 (file)
@@ -342,10 +342,7 @@ namespace System {
 
                internal static bool ValidDigit (char e, bool allowHex)
                {
-                       if (allowHex)
-                               return Char.IsDigit (e) || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
-
-                       return Char.IsDigit (e);
+                       return (e >= '0' && e <= '9') || (allowHex &&  (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f'));
                }
                
                internal static Exception GetFormatException ()
index 9975296579f109d443e8aba3e865f6dc2060127c..506a6cbf86fffb7068027a505e9012f2d2ada313 100644 (file)
@@ -252,6 +252,18 @@ public class Int32Test
                        Assert.IsTrue (typeof (ArgumentException) == e.GetType (), "C#42");
                }
 
+               try {
+                       Int32.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
+                       Assert.Fail ("C#42");
+               } catch (FormatException) {
+               }
+
+               try {
+                       Int32.Parse ("\xFF15\xFF15", NumberStyles.Any, CultureInfo.InvariantCulture);
+                       Assert.Fail ("C#43");
+               } catch (FormatException) {
+               }
+
                // Pass a DateTimeFormatInfo, it is unable to format
                // numbers, but we should not crash
                
@@ -333,7 +345,7 @@ public class Int32Test
                        Int32.Parse ("2.09E1",  NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent);
                        Assert.Fail ("B#9");
                } catch (OverflowException) {
-               }               
+               }
        }
 
        [Test]
index 3943969c65a7aaeec85d1ffc71d4d3b71355e8c0..b12395ea0c084875dcd7c42d8b3363561fcf0e60 100644 (file)
@@ -308,6 +308,12 @@ public class Int64Test
                Assert.IsTrue(typeof(OverflowException) == e.GetType(), "#20");
        }
 
+               try {
+                       Int64.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
+                       Assert.Fail ("C#42");
+               } catch (FormatException) {
+               }
+
        // Pass a DateTimeFormatInfo, it is unable to format
        // numbers, but we should not crash
        
index 6a730d2c737077283d0b59d656995aaa7166a91c..2ae0d55a3de6b10dac93e89a0eb7b0ebcf485cb8 100644 (file)
@@ -188,13 +188,17 @@ public class UInt32Test
                try {
                        UInt32.Parse("$42", NumberStyles.Integer, Nfi);
                        Assert.Fail("Should raise a System.FormatException");
+               } catch (FormatException e) {
                }
-               catch (Exception e) {
-                       Assert.IsTrue(typeof(FormatException) == e.GetType());
+
+               try {
+                       UInt32.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
+                       Assert.Fail ("C#42");
+               } catch (FormatException) {
                }
+
                // Pass a DateTimeFormatInfo, it is unable to format
-               // numbers, but we should not crash
-               
+               // numbers, but we should not crash             
                UInt32.Parse ("123", new DateTimeFormatInfo ());
 
                Assert.AreEqual (734561, UInt32.Parse ("734561\0"), "C#43");
index dda949c4022e60f899aa78fa0f417d912497ee0c..7633fea270fa99273483a29e4b40fbf9d4ca6802 100644 (file)
@@ -176,14 +176,17 @@ public class UInt64Test
                try {
                        UInt64.Parse("$42", NumberStyles.Integer, Nfi);
                        Assert.Fail("Should raise a System.FormatException");
+               } catch (FormatException e) {
                }
-               catch (Exception e) {
-                       Assert.IsTrue(typeof(FormatException) == e.GetType());
+
+               try {
+                       UInt64.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
+                       Assert.Fail ("C#42");
+               } catch (FormatException) {
                }
 
                // Pass a DateTimeFormatInfo, it is unable to format
-               // numbers, but we should not crash
-               
+               // numbers, but we should not crash             
                UInt64.Parse ("123", new DateTimeFormatInfo ());
 
                Assert.AreEqual (734561, UInt64.Parse ("734561\0"), "C#43");