]> granicus.if.org Git - python/commitdiff
bpo-34087: Backport tests for int/float/complex (GH-8274)
authorINADA Naoki <methane@users.noreply.github.com>
Sat, 14 Jul 2018 07:38:14 +0000 (16:38 +0900)
committerGitHub <noreply@github.com>
Sat, 14 Jul 2018 07:38:14 +0000 (16:38 +0900)
Cherrypick tests from 16dfca4d829e45f36e71bf43f83226659ce49315

While the regression is not in 3.6, it's worth to backport test cases
to 3.6 branch too.

Lib/test/test_complex.py
Lib/test/test_float.py
Lib/test/test_long.py
Python/pystrtod.c

index cee49343e268a23c76f37c305d398eb29be423fb..1980fc4092644e8b87ddf0b57a7ff09d89ec8239 100644 (file)
@@ -345,6 +345,9 @@ class ComplexTest(unittest.TestCase):
         self.assertEqual(type(complex("1"*500)), complex)
         # check whitespace processing
         self.assertEqual(complex('\N{EM SPACE}(\N{EN SPACE}1+1j ) '), 1+1j)
+        # Invalid unicode string
+        # See bpo-34087
+        self.assertRaises(ValueError, complex, '\u3053\u3093\u306b\u3061\u306f')
 
         class EvilExc(Exception):
             pass
index c5ca50c8f71206d5b3e55a053bacd6f5e90817af..61551e5c99031ba7ea07cdd79576600877e0f971 100644 (file)
@@ -60,6 +60,9 @@ class GeneralFloatCases(unittest.TestCase):
         # extra long strings should not be a problem
         float(b'.' + b'1'*1000)
         float('.' + '1'*1000)
+        # Invalid unicode string
+        # See bpo-34087
+        self.assertRaises(ValueError, float, '\u3053\u3093\u306b\u3061\u306f')
 
     def test_underscores(self):
         for lit in VALID_UNDERSCORE_LITERALS:
index fd15f04aceca8fc7f15298a8fe0e40d9add08a06..140ace18dd1e797bda58900b68c2b0652c7ab0b5 100644 (file)
@@ -373,6 +373,10 @@ class LongTest(unittest.TestCase):
         for base in invalid_bases:
             self.assertRaises(ValueError, int, '42', base)
 
+        # Invalid unicode string
+        # See bpo-34087
+        self.assertRaises(ValueError, int, '\u3053\u3093\u306b\u3061\u306f')
+
 
     def test_conversion(self):
 
index 64d0c52e4879583c2aec5cb806c4723eb04184cc..58278c24be9c280d4cf4b5994f91b924513e0a04 100644 (file)
@@ -391,6 +391,8 @@ _Py_string_to_number_with_underscores(
     char *dup, *end;
     PyObject *result;
 
+    assert(s[orig_len] == '\0');
+
     if (strchr(s, '_') == NULL) {
         return innerfunc(s, orig_len, arg);
     }