]> granicus.if.org Git - python/commitdiff
SF bug [#455775] float parsing discrepancy.
authorTim Peters <tim.peters@gmail.com>
Mon, 27 Aug 2001 19:19:28 +0000 (19:19 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 27 Aug 2001 19:19:28 +0000 (19:19 +0000)
PyTokenizer_Get:  error if exponent contains no digits (3e, 2.0e+, ...).

Lib/test/test_compile.py
Parser/tokenizer.c

index 17d35006ea5fc710c9c37151cb1e7d1c9a5730dd..0276ba6bee620fc6ca7005cb711a737f7277ec08 100644 (file)
@@ -50,3 +50,18 @@ try:
     raise TestFailed, "non-default args after default"
 except SyntaxError:
     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")
index 23979690045f85ea4730b45ea57dc4b427248da2..7270629b19b68867ab585de70049313313061b31 100644 (file)
@@ -756,9 +756,7 @@ PyTokenizer_Get(register struct tok_state *tok, char **p_start,
                        if (c == 'l' || c == 'L')
                                c = tok_nextc(tok);
                        else {
-                               /* Accept floating point numbers.
-                                  XXX This accepts incomplete things like
-                                  XXX 12e or 1e+; worry run-time */
+                               /* Accept floating point numbers. */
                                if (c == '.') {
                fraction:
                                        /* Fraction */
@@ -771,9 +769,14 @@ PyTokenizer_Get(register struct tok_state *tok, char **p_start,
                                        c = tok_nextc(tok);
                                        if (c == '+' || c == '-')
                                                c = tok_nextc(tok);
-                                       while (isdigit(c)) {
-                                               c = tok_nextc(tok);
+                                       if (!isdigit(c)) {
+                                               tok->done = E_TOKEN;
+                                               tok_backup(tok, c);
+                                               return ERRORTOKEN;
                                        }
+                                       do {
+                                               c = tok_nextc(tok);
+                                       } while (isdigit(c));
                                }
 #ifndef WITHOUT_COMPLEX
                                if (c == 'j' || c == 'J')