diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2020-04-12 18:21:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-12 18:21:00 (GMT) |
commit | 41d5b94af44e34ac05d4cd57460ed104ccf96628 (patch) | |
tree | 564847a328b623cc02268a93fda371e0bea797b3 | |
parent | 402e1cdb132f384e4dcde7a3d7ec7ea1fc7ab527 (diff) | |
download | cpython-41d5b94af44e34ac05d4cd57460ed104ccf96628.zip cpython-41d5b94af44e34ac05d4cd57460ed104ccf96628.tar.gz cpython-41d5b94af44e34ac05d4cd57460ed104ccf96628.tar.bz2 |
bpo-40246: Report a better error message for invalid string prefixes (GH-19476)
-rw-r--r-- | Include/errcode.h | 1 | ||||
-rw-r--r-- | Lib/test/test_fstring.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2020-04-11-17-52-03.bpo-40246.vXPze5.rst | 1 | ||||
-rw-r--r-- | Parser/tokenizer.c | 4 | ||||
-rw-r--r-- | Python/pythonrun.c | 3 |
5 files changed, 10 insertions, 1 deletions
diff --git a/Include/errcode.h b/Include/errcode.h index b37cd26..9af8d5c 100644 --- a/Include/errcode.h +++ b/Include/errcode.h @@ -31,6 +31,7 @@ extern "C" { #define E_LINECONT 25 /* Unexpected characters after a line continuation */ #define E_IDENTIFIER 26 /* Invalid characters in identifier */ #define E_BADSINGLE 27 /* Ill-formed single statement input */ +#define E_BADPREFIX 28 /* Bad string prefixes */ #ifdef __cplusplus } diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index 4966392..ef0ccb8 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -841,7 +841,7 @@ non-important content self.assertEqual(f'{f"{y}"*3}', '555') def test_invalid_string_prefixes(self): - self.assertAllRaise(SyntaxError, 'unexpected EOF while parsing', + self.assertAllRaise(SyntaxError, 'invalid string prefix', ["fu''", "uf''", "Fu''", diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-04-11-17-52-03.bpo-40246.vXPze5.rst b/Misc/NEWS.d/next/Core and Builtins/2020-04-11-17-52-03.bpo-40246.vXPze5.rst new file mode 100644 index 0000000..056b7f8 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-04-11-17-52-03.bpo-40246.vXPze5.rst @@ -0,0 +1 @@ +Report a specialized error message, `invalid string prefix`, when the tokenizer encounters a string with an invalid prefix.
\ No newline at end of file diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index c650442..97986aa 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -1392,6 +1392,10 @@ tok_get(struct tok_state *tok, const char **p_start, const char **p_end) if (nonascii && !verify_identifier(tok)) { return ERRORTOKEN; } + if (c == '"' || c == '\'') { + tok->done = E_BADPREFIX; + return ERRORTOKEN; + } *p_start = tok->start; *p_end = tok->cur; diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 95571a8..eb9159f 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1574,6 +1574,9 @@ err_input(perrdetail *err) case E_BADSINGLE: msg = "multiple statements found while compiling a single statement"; break; + case E_BADPREFIX: + msg = "invalid string prefix"; + break; default: fprintf(stderr, "error=%d\n", err->error); msg = "unknown parsing error"; |