mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
SF bug [#455775] float parsing discrepancy.
PyTokenizer_Get: error if exponent contains no digits (3e, 2.0e+, ...).
This commit is contained in:
parent
de1d4957c0
commit
9aa70d93aa
2 changed files with 23 additions and 5 deletions
|
@ -50,3 +50,18 @@ try:
|
||||||
raise TestFailed, "non-default args after default"
|
raise TestFailed, "non-default args after default"
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print "testing bad float literals"
|
||||||
|
|
||||||
|
def expect_error(s):
|
||||||
|
try:
|
||||||
|
eval(s)
|
||||||
|
raise TestFailed("%r accepted" % s)
|
||||||
|
except SyntaxError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
expect_error("2e")
|
||||||
|
expect_error("2.0e+")
|
||||||
|
expect_error("1e-")
|
||||||
|
expect_error("3-4e/21")
|
||||||
|
|
|
@ -756,9 +756,7 @@ PyTokenizer_Get(register struct tok_state *tok, char **p_start,
|
||||||
if (c == 'l' || c == 'L')
|
if (c == 'l' || c == 'L')
|
||||||
c = tok_nextc(tok);
|
c = tok_nextc(tok);
|
||||||
else {
|
else {
|
||||||
/* Accept floating point numbers.
|
/* Accept floating point numbers. */
|
||||||
XXX This accepts incomplete things like
|
|
||||||
XXX 12e or 1e+; worry run-time */
|
|
||||||
if (c == '.') {
|
if (c == '.') {
|
||||||
fraction:
|
fraction:
|
||||||
/* Fraction */
|
/* Fraction */
|
||||||
|
@ -771,9 +769,14 @@ PyTokenizer_Get(register struct tok_state *tok, char **p_start,
|
||||||
c = tok_nextc(tok);
|
c = tok_nextc(tok);
|
||||||
if (c == '+' || c == '-')
|
if (c == '+' || c == '-')
|
||||||
c = tok_nextc(tok);
|
c = tok_nextc(tok);
|
||||||
while (isdigit(c)) {
|
if (!isdigit(c)) {
|
||||||
c = tok_nextc(tok);
|
tok->done = E_TOKEN;
|
||||||
|
tok_backup(tok, c);
|
||||||
|
return ERRORTOKEN;
|
||||||
}
|
}
|
||||||
|
do {
|
||||||
|
c = tok_nextc(tok);
|
||||||
|
} while (isdigit(c));
|
||||||
}
|
}
|
||||||
#ifndef WITHOUT_COMPLEX
|
#ifndef WITHOUT_COMPLEX
|
||||||
if (c == 'j' || c == 'J')
|
if (c == 'j' || c == 'J')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue