Skip to content

Commit 855be47

Browse files
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 ee70c70) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com> Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
1 parent 0b7aae8 commit 855be47

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Lib/test/test_fstring.py

+1
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ def test_mismatched_braces(self):
10551055
"f'{'",
10561056
"f'x{<'", # See bpo-46762.
10571057
"f'x{>'",
1058+
"f'{i='", # See gh-93418.
10581059
])
10591060

10601061
# But these are just normal strings.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed an assert where an f-string has an equal sign '=' following an
2+
expression, but there's no trailing brace. For example, f"{i=".

Parser/string_parser.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,9 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec
740740
while (Py_ISSPACE(**str)) {
741741
*str += 1;
742742
}
743-
743+
if (*str >= end) {
744+
goto unexpected_end_of_string;
745+
}
744746
/* Set *expr_text to the text of the expression. */
745747
*expr_text = PyUnicode_FromStringAndSize(expr_start, *str-expr_start);
746748
if (!*expr_text) {

0 commit comments

Comments
 (0)