From: INADA Naoki Date: Sat, 14 Jul 2018 07:38:14 +0000 (+0900) Subject: bpo-34087: Backport tests for int/float/complex (GH-8274) X-Git-Tag: v3.6.7rc1~177 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b2f8aa0c998d331ab2b4c701756a6427c0e91d48;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index cee49343e268..1980fc409264 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 c5ca50c8f712..61551e5c9903 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 fd15f04aceca..140ace18dd1e 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 64d0c52e4879..58278c24be9c 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); }