[Python-checkins] r47212 - in python/trunk: Lib/test/test__locale.py Lib/test/test_builtin.py Misc/NEWS Python/pystrtod.c

martin.v.loewis python-checkins at python.org
Mon Jul 3 14:19:51 CEST 2006


Author: martin.v.loewis
Date: Mon Jul  3 14:19:50 2006
New Revision: 47212

Modified:
   python/trunk/Lib/test/test__locale.py
   python/trunk/Lib/test/test_builtin.py
   python/trunk/Misc/NEWS
   python/trunk/Python/pystrtod.c
Log:
Bug #1417699: Reject locale-specific decimal point in float()
and atof().


Modified: python/trunk/Lib/test/test__locale.py
==============================================================================
--- python/trunk/Lib/test/test__locale.py	(original)
+++ python/trunk/Lib/test/test__locale.py	Mon Jul  3 14:19:50 2006
@@ -113,6 +113,9 @@
                                 "using eval('3.14') failed for %s" % loc)
             self.assertEquals(int(float('3.14') * 100), 314,
                                 "using float('3.14') failed for %s" % loc)
+            if localeconv()['decimal_point'] != '.':
+                self.assertRaises(ValueError, float,
+                                  localeconv()['decimal_point'].join(['1', '23']))
 
 def test_main():
     run_unittest(_LocaleTests)

Modified: python/trunk/Lib/test/test_builtin.py
==============================================================================
--- python/trunk/Lib/test/test_builtin.py	(original)
+++ python/trunk/Lib/test/test_builtin.py	Mon Jul  3 14:19:50 2006
@@ -558,13 +558,24 @@
     @run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE')
     def test_float_with_comma(self):
         # set locale to something that doesn't use '.' for the decimal point
+        # float must not accept the locale specific decimal point but
+        # it still has to accept the normal python syntac
         import locale
         if not locale.localeconv()['decimal_point'] == ',':
             return
 
-        self.assertEqual(float("  3,14  "), 3.14)
-        self.assertEqual(float("  +3,14  "), 3.14)
-        self.assertEqual(float("  -3,14  "), -3.14)
+        self.assertEqual(float("  3.14  "), 3.14)
+        self.assertEqual(float("+3.14  "), 3.14)
+        self.assertEqual(float("-3.14  "), -3.14)
+        self.assertEqual(float(".14  "), .14)
+        self.assertEqual(float("3.  "), 3.0)
+        self.assertEqual(float("3.e3  "), 3000.0)
+        self.assertEqual(float("3.2e3  "), 3200.0)
+        self.assertEqual(float("2.5e-1  "), 0.25)
+        self.assertEqual(float("5e-1"), 0.5)
+        self.assertRaises(ValueError, float, "  3,14  ")
+        self.assertRaises(ValueError, float, "  +3,14  ")
+        self.assertRaises(ValueError, float, "  -3,14  ")
         self.assertRaises(ValueError, float, "  0x3.1  ")
         self.assertRaises(ValueError, float, "  -0x3.p-1  ")
         self.assertEqual(float("  25.e-1  "), 2.5)

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Mon Jul  3 14:19:50 2006
@@ -12,6 +12,9 @@
 Core and builtins
 -----------------
 
+- Bug #1417699: Reject locale-specific decimal point in float()
+  and atof().
+
 - Bug #1511381: codec_getstreamcodec() in codec.c is corrected to
   omit a default "error" argument for NULL pointer.  This allows
   the parser to take a codec from cjkcodecs again.

Modified: python/trunk/Python/pystrtod.c
==============================================================================
--- python/trunk/Python/pystrtod.c	(original)
+++ python/trunk/Python/pystrtod.c	Mon Jul  3 14:19:50 2006
@@ -90,6 +90,13 @@
 				p++;
 			end = p;
 		}
+		else if (strncmp(p, decimal_point, decimal_point_len) == 0)
+		{
+			/* Python bug #1417699 */
+			*endptr = (char*)nptr;
+			errno = EINVAL;
+			return val;
+		}
 		/* For the other cases, we need not convert the decimal point */
 	}
 


More information about the Python-checkins mailing list