From 0fb174a5c74b1309b9c9034de08a17d94d06ba9b Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 14 Jul 2018 12:06:43 +0900 Subject: [PATCH] bpo-34087: Backport test added by (GH-8274) GH-8276 fixed regression in 3.7. 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 cee49343e268a2..1980fc4092644e 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -345,6 +345,9 @@ def split_zeros(x): 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 c5ca50c8f71206..61551e5c99031b 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -60,6 +60,9 @@ def test_float(self): # 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 fd15f04aceca8f..140ace18dd1e79 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -373,6 +373,10 @@ def test_long(self): 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 64d0c52e487958..58278c24be9c28 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); }