[Python-checkins] gh-93418: Fix an assert when an f-string expression is followed by an '=', but no closing brace. (gh-93419) (gh-93423)

ericvsmith webhook-mailer at python.org
Wed Jun 1 21:04:47 EDT 2022


https://github.com/python/cpython/commit/855be47a02e68bf9217ef8ab79dbd94ddc3298f1
commit: 855be47a02e68bf9217ef8ab79dbd94ddc3298f1
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ericvsmith <ericvsmith at users.noreply.github.com>
date: 2022-06-01T21:04:43-04:00
summary:

gh-93418: Fix an assert when an f-string expression is followed by an '=', but no closing brace. (gh-93419) (gh-93423)

(cherry picked from commit ee70c70aa93d7a41cbe47a0b361b17f9d7ec8acd)

Co-authored-by: Eric V. Smith <ericvsmith at users.noreply.github.com>

Co-authored-by: Eric V. Smith <ericvsmith at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2022-06-01-17-47-40.gh-issue-93418.24dJuc.rst
M Lib/test/test_fstring.py
M Parser/string_parser.c

diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 0c255c2af2217..8f3b609d33bc9 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -1055,6 +1055,7 @@ def test_mismatched_braces(self):
                              "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
index 0000000000000..74ad06bfeee7c
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-01-17-47-40.gh-issue-93418.24dJuc.rst	
@@ -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=".
diff --git a/Parser/string_parser.c b/Parser/string_parser.c
index dac8dbb846471..80f158b5a65be 100644
--- a/Parser/string_parser.c
+++ b/Parser/string_parser.c
@@ -740,7 +740,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) {



More information about the Python-checkins mailing list