diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index 0c255c2af22179bc50711a72ebc987c1a013fcb8..8f3b609d33bc971263a4f466b3fa7ae9ca13019b 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -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. diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-01-17-47-40.gh-issue-93418.24dJuc.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-01-17-47-40.gh-issue-93418.24dJuc.rst new file mode 100644 index 0000000000000000000000000000000000000000..74ad06bfeee7c4f08f88318988a80fb06f3195f3 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-01-17-47-40.gh-issue-93418.24dJuc.rst @@ -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=". diff --git a/Parser/string_parser.c b/Parser/string_parser.c index dac8dbb846471a27ae557b992fe5aee08e16a2d6..80f158b5a65be3682b76c4c780a0eb54a7837e32 100644 --- a/Parser/string_parser.c +++ b/Parser/string_parser.c @@ -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) {