]> 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...
authorEric V. Smith <ericvsmith@users.noreply.github.com>
Wed, 1 Jun 2022 23:20:06 +0000 (19:20 -0400)
committerGitHub <noreply@github.com>
Wed, 1 Jun 2022 23:20:06 +0000 (19:20 -0400)
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 e8bf420d699ed0b67cdd75e775ad070654e6a113..9815b7c28f2f40dd4ee54a4b74e071aee730f616 100644 (file)
@@ -1084,6 +1084,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 c56ed20ad4cfc23640644cbe76986cd57ae9aa3c..984c05d39c1a1735dddbe783d39ed01fd4ffd302 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) {