diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 1b8e6054d7f5a8..c200e07b2a346e 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -497,6 +497,12 @@ def test(f, format_spec, result): test(0.01, '', '0.01') test(0.01, 'g', '0.01') + # test for issue 3411 + test(1.23, '1', '1.23') + test(-1.23, '1', '-1.23') + test(1.23, '1g', '1.23') + test(-1.23, '1g', '-1.23') + test( 1.0, ' g', ' 1') test(-1.0, ' g', '-1') test( 1.0, '+g', '+1') diff --git a/Python/pystrtod.c b/Python/pystrtod.c index 5a96b58e15fc45..b3738528dbfe7f 100644 --- a/Python/pystrtod.c +++ b/Python/pystrtod.c @@ -302,6 +302,10 @@ ensure_decimal_point(char* buffer, size_t buf_size) /* search for the first non-digit character */ char *p = buffer; + if (*p == '-' || *p == '+') + /* Skip leading sign, if present. I think this could only + ever be '-', but it can't hurt to check for both. */ + ++p; while (*p && isdigit(Py_CHARMASK(*p))) ++p;