mirror of https://github.com/python/cpython
bpo-40246: Report a better error message for invalid string prefixes (GH-19476)
This commit is contained in:
parent
402e1cdb13
commit
41d5b94af4
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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''",
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Report a specialized error message, `invalid string prefix`, when the tokenizer encounters a string with an invalid prefix.
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue