diff options
author | Meador Inge <meadori@gmail.com> | 2012-01-19 07:08:41 (GMT) |
---|---|---|
committer | Meador Inge <meadori@gmail.com> | 2012-01-19 07:08:41 (GMT) |
commit | fa21bf015d4e9cb0c010fde28db0c344174634d1 (patch) | |
tree | 449cbadc11a8420aa3cb8db9678dded1d9176599 /Parser | |
parent | 00c7f85298b9803371b4a0019ce8732ed8a2dd3b (diff) | |
download | cpython-fa21bf015d4e9cb0c010fde28db0c344174634d1.zip cpython-fa21bf015d4e9cb0c010fde28db0c344174634d1.tar.gz cpython-fa21bf015d4e9cb0c010fde28db0c344174634d1.tar.bz2 |
Issue #12705: Raise SyntaxError when compiling multiple statements as single interactive statement
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/parsetok.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Parser/parsetok.c b/Parser/parsetok.c index f22ac67..9b2d730 100644 --- a/Parser/parsetok.c +++ b/Parser/parsetok.c @@ -224,6 +224,23 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, if (err_ret->error == E_DONE) { n = ps->p_tree; ps->p_tree = NULL; + + /* Check that the source for a single input statement really + is a single statement by looking at what is left in the + buffer after parsing. Trailing whitespace and comments + are OK. */ + if (start == single_input) { + char *cur = tok->cur; + char c = *tok->cur; + + while (c == ' ' || c == '\t' || c == '\n' || c == '\014') + c = *++cur; + + if (c && c != '#') { + err_ret->error = E_BADSINGLE; + n = NULL; + } + } } else n = NULL; |