]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40246: Report a better error message for invalid string prefixes (GH-19476)
authorLysandros Nikolaou <lisandrosnik@gmail.com>
Sun, 12 Apr 2020 18:21:00 +0000 (21:21 +0300)
committerGitHub <noreply@github.com>
Sun, 12 Apr 2020 18:21:00 +0000 (19:21 +0100)
Include/errcode.h
Lib/test/test_fstring.py
Misc/NEWS.d/next/Core and Builtins/2020-04-11-17-52-03.bpo-40246.vXPze5.rst [new file with mode: 0644]
Parser/tokenizer.c
Python/pythonrun.c

index b37cd261d5ec4d54ac6b8ca9fd6008e70e35859a..9af8d5c03d59ba0259fd7c94319a8e7f981f04e7 100644 (file)
@@ -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
 }
index 49663923e7f5aa2e52c04a4e01514d4bc0d05459..ef0ccb8cf53c100940c9e10c1204b5dcaf266a74 100644 (file)
@@ -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 (file)
index 0000000..056b7f8
--- /dev/null
@@ -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
index c650442a4a7fb8c4abf9d0415273dc00cabea793..97986aa8ef40aac72f5964d2efea03a1dabc57cc 100644 (file)
@@ -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;
 
index 95571a8c7518a14d720e40448c3a80bb12893130..eb9159f1b5c522c8296c171e7a45024f54675ffb 100644 (file)
@@ -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";