From b2f8aa0c998d331ab2b4c701756a6427c0e91d48 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 14 Jul 2018 16:38:14 +0900 Subject: [PATCH] bpo-34087: Backport tests for int/float/complex (GH-8274) 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 | 3 +++ Lib/test/test_float.py | 3 +++ Lib/test/test_long.py | 4 ++++ Python/pystrtod.c | 2 ++ 4 files changed, 12 insertions(+) diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index cee49343e2..1980fc4092 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -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 diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index c5ca50c8f7..61551e5c99 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -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: diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index fd15f04ace..140ace18dd 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -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): diff --git a/Python/pystrtod.c b/Python/pystrtod.c index 64d0c52e48..58278c24be 100644 --- a/Python/pystrtod.c +++ b/Python/pystrtod.c @@ -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); } -- 2.40.0