Skip to content

Commit ee70c70

Browse files
authored
gh-93418: Fix an assert when an f-string expression is followed by an '=', but no closing brace. (gh-93419)
1 parent 8a221a8 commit ee70c70

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
@@ -1084,6 +1084,7 @@ def test_mismatched_braces(self):
10841084
"f'{'",
10851085
"f'x{<'", # See bpo-46762.
10861086
"f'x{>'",
1087+
"f'{i='", # See gh-93418.
10871088
])
10881089

10891090
# 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
@@ -756,7 +756,9 @@ fstring_find_expr(Parser *p, const char **str, const char *end, int raw, int rec
756756
while (Py_ISSPACE(**str)) {
757757
*str += 1;
758758
}
759-
759+
if (*str >= end) {
760+
goto unexpected_end_of_string;
761+
}
760762
/* Set *expr_text to the text of the expression. */
761763
*expr_text = PyUnicode_FromStringAndSize(expr_start, *str-expr_start);
762764
if (!*expr_text) {

0 commit comments

Comments
 (0)