Skip to content

Commit

Permalink
gh-93418: Fix an assert when an f-string expression is followed by an…
Browse files Browse the repository at this point in the history
… '=', 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>
  • Loading branch information
miss-islington and ericvsmith committed Jun 2, 2022
1 parent 0b7aae8 commit 855be47
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Lib/test/test_fstring.py
Expand Up @@ -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.
Expand Down
@@ -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
Expand Up @@ -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) {
Expand Down

0 comments on commit 855be47

Please sign in to comment.