Skip to content

Commit 376d537

Browse files
gh-93418: Fix an assert when an f-string expression is followed by an '=', but no closing brace. (gh-93419) (gh-93422)
(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 ae0cf8e commit 376d537

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
@@ -1073,6 +1073,7 @@ def test_mismatched_braces(self):
10731073
"f'{'",
10741074
"f'x{<'", # See bpo-46762.
10751075
"f'x{>'",
1076+
"f'{i='", # See gh-93418.
10761077
])
10771078

10781079
# 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)