Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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=".
4 changes: 3 additions & 1 deletion Parser/string_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down