]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-93418: Fix an assert when an f-string expression is followed by an '=', but no...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 2 Jun 2022 01:04:27 +0000 (18:04 -0700)
committerGitHub <noreply@github.com>
Thu, 2 Jun 2022 01:04:27 +0000 (21:04 -0400)
(cherry picked from commit ee70c70aa93d7a41cbe47a0b361b17f9d7ec8acd)

Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
Lib/test/test_fstring.py
Misc/NEWS.d/next/Core and Builtins/2022-06-01-17-47-40.gh-issue-93418.24dJuc.rst [new file with mode: 0644]
Parser/string_parser.c

index 0c3372f0335517f90ade734b4dd73ffd5f9d4e85..93aa229709a0a5cfd1c076533367639323ff5c01 100644 (file)
@@ -1073,6 +1073,7 @@ x = (
                              "f'{'",
                              "f'x{<'",  # See bpo-46762.
                              "f'x{>'",
+                             "f'{i='",  # See gh-93418.
                              ])
 
         # But these are just normal strings.
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-01-17-47-40.gh-issue-93418.24dJuc.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-01-17-47-40.gh-issue-93418.24dJuc.rst
new file mode 100644 (file)
index 0000000..74ad06b
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed an assert where an f-string has an equal sign '=' following an
+expression, but there's no trailing brace. For example, f"{i=".
index 9c12d8ca101d00f63d3684aa5ad1997a0ac9e249..5e94d477bc04a83d6dd644da22820fd2332094b7 100644 (file)
@@ -756,7 +756,9 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec
         while (Py_ISSPACE(**str)) {
             *str += 1;
         }
-
+        if (*str >= end) {
+            goto unexpected_end_of_string;
+        }
         /* Set *expr_text to the text of the expression. */
         *expr_text = PyUnicode_FromStringAndSize(expr_start, *str-expr_start);
         if (!*expr_text) {